Diff
Modified: trunk/Source/WebKit2/ChangeLog (158462 => 158463)
--- trunk/Source/WebKit2/ChangeLog 2013-11-01 23:24:40 UTC (rev 158462)
+++ trunk/Source/WebKit2/ChangeLog 2013-11-01 23:24:49 UTC (rev 158463)
@@ -96,6 +96,20 @@
2013-11-01 Tim Horton <timothy_hor...@apple.com>
+ Remote Layer Tree: Move RemoteLayerBackingStore to Shared/
+ https://bugs.webkit.org/show_bug.cgi?id=123646
+
+ Reviewed by Darin Adler.
+
+ Move RemoteLayerBackingStore to Shared/, since it is
+ used on both the UI and Web process side of things.
+
+ * Shared/mac/RemoteLayerBackingStore.h: Renamed from Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.h.
+ * Shared/mac/RemoteLayerBackingStore.mm: Renamed from Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.mm.
+ * WebKit2.xcodeproj/project.pbxproj:
+
+2013-11-01 Tim Horton <timothy_hor...@apple.com>
+
Remote Layer Tree: Vend layer contents via IOSurfaces
https://bugs.webkit.org/show_bug.cgi?id=123600
Copied: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h (from rev 158449, trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.h) (0 => 158463)
--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h (rev 0)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.h 2013-11-01 23:24:49 UTC (rev 158463)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef RemoteLayerBackingStore_h
+#define RemoteLayerBackingStore_h
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#include "ShareableBitmap.h"
+#include <WebCore/FloatRect.h>
+#include <WebCore/Region.h>
+
+namespace WebKit {
+
+class PlatformCALayerRemote;
+
+class RemoteLayerBackingStore {
+public:
+ RemoteLayerBackingStore();
+
+ void ensureBackingStore(PlatformCALayerRemote*, WebCore::IntSize, float scale, bool acceleratesDrawing);
+
+ void setNeedsDisplay(const WebCore::IntRect);
+ void setNeedsDisplay();
+
+ bool display();
+
+ RetainPtr<CGImageRef> image() const;
+ RetainPtr<IOSurfaceRef> surface() const { return m_frontSurface; }
+ WebCore::IntSize size() const { return m_size; }
+ float scale() const { return m_scale; }
+ bool acceleratesDrawing() const { return m_acceleratesDrawing; }
+
+ PlatformCALayerRemote* layer() const { return m_layer; }
+
+ void encode(CoreIPC::ArgumentEncoder&) const;
+ static bool decode(CoreIPC::ArgumentDecoder&, RemoteLayerBackingStore&);
+
+private:
+ WebCore::IntRect mapToContentCoordinates(const WebCore::IntRect) const;
+
+ bool hasFrontBuffer() { return m_acceleratesDrawing ? !!m_frontSurface : !!m_frontBuffer; }
+
+ std::unique_ptr<WebCore::GraphicsContext> createBackingStore();
+ void drawInContext(WebCore::GraphicsContext&);
+
+ PlatformCALayerRemote* m_layer;
+
+ WebCore::IntSize m_size;
+ float m_scale;
+
+ WebCore::Region m_dirtyRegion;
+
+ RefPtr<ShareableBitmap> m_frontBuffer;
+ RetainPtr<IOSurfaceRef> m_frontSurface;
+
+ bool m_acceleratesDrawing;
+};
+
+} // namespace WebKit
+
+#endif // USE(ACCELERATED_COMPOSITING)
+
+#endif // RemoteLayerBackingStore_h
Copied: trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm (from rev 158449, trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.mm) (0 => 158463)
--- trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm (rev 0)
+++ trunk/Source/WebKit2/Shared/mac/RemoteLayerBackingStore.mm 2013-11-01 23:24:49 UTC (rev 158463)
@@ -0,0 +1,306 @@
+ /*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "RemoteLayerBackingStore.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#import "ArgumentCoders.h"
+#import "MachPort.h"
+#import "PlatformCALayerRemote.h"
+#import "ShareableBitmap.h"
+#import "WebCoreArgumentCoders.h"
+#import <WebCore/GraphicsContextCG.h>
+#import <WebCore/WebLayer.h>
+
+#ifdef __has_include
+#if __has_include(<ApplicationServices/ApplicationServicesPriv.h>)
+#import <ApplicationServices/ApplicationServicesPriv.h>
+#endif
+#endif
+
+extern "C" {
+CGContextRef CGIOSurfaceContextCreate(IOSurfaceRef, size_t, size_t, size_t, size_t, CGColorSpaceRef, CGBitmapInfo);
+CGImageRef CGIOSurfaceContextCreateImage(CGContextRef);
+}
+
+using namespace WebCore;
+using namespace WebKit;
+
+RemoteLayerBackingStore::RemoteLayerBackingStore()
+ : m_layer(nullptr)
+{
+}
+
+void RemoteLayerBackingStore::ensureBackingStore(PlatformCALayerRemote* layer, IntSize size, float scale, bool acceleratesDrawing)
+{
+ if (m_layer == layer && m_size == size && m_scale == scale && m_acceleratesDrawing == acceleratesDrawing)
+ return;
+
+ m_layer = layer;
+ m_size = size;
+ m_scale = scale;
+ m_acceleratesDrawing = acceleratesDrawing;
+
+ m_frontSurface = nullptr;
+ m_frontBuffer = nullptr;
+}
+
+void RemoteLayerBackingStore::encode(CoreIPC::ArgumentEncoder& encoder) const
+{
+ encoder << m_size;
+ encoder << m_scale;
+ encoder << m_acceleratesDrawing;
+
+ if (m_acceleratesDrawing) {
+ mach_port_t port = IOSurfaceCreateMachPort(m_frontSurface.get());
+ encoder << CoreIPC::MachPort(port, MACH_MSG_TYPE_MOVE_SEND);
+ } else {
+ ShareableBitmap::Handle handle;
+ m_frontBuffer->createHandle(handle);
+ encoder << handle;
+ }
+}
+
+bool RemoteLayerBackingStore::decode(CoreIPC::ArgumentDecoder& decoder, RemoteLayerBackingStore& result)
+{
+ if (!decoder.decode(result.m_size))
+ return false;
+
+ if (!decoder.decode(result.m_scale))
+ return false;
+
+ if (!decoder.decode(result.m_acceleratesDrawing))
+ return false;
+
+ if (result.m_acceleratesDrawing) {
+ CoreIPC::MachPort machPort;
+ if (!decoder.decode(machPort))
+ return false;
+ result.m_frontSurface = adoptCF(IOSurfaceLookupFromMachPort(machPort.port()));
+ mach_port_deallocate(mach_task_self(), machPort.port());
+ } else {
+ ShareableBitmap::Handle handle;
+ if (!decoder.decode(handle))
+ return false;
+ result.m_frontBuffer = ShareableBitmap::create(handle);
+ }
+
+ return true;
+}
+
+IntRect RemoteLayerBackingStore::mapToContentCoordinates(const IntRect rect) const
+{
+ IntRect flippedRect = rect;
+ if (m_layer->owner()->platformCALayerContentsOrientation() == GraphicsLayer::CompositingCoordinatesBottomUp)
+ flippedRect.setY(m_size.height() - rect.y() - rect.height());
+ return flippedRect;
+}
+
+void RemoteLayerBackingStore::setNeedsDisplay(const IntRect rect)
+{
+ IntRect flippedRect = mapToContentCoordinates(rect);
+ m_dirtyRegion.unite(flippedRect);
+}
+
+void RemoteLayerBackingStore::setNeedsDisplay()
+{
+ setNeedsDisplay(IntRect(IntPoint(), m_size));
+}
+
+static RetainPtr<CGContextRef> createIOSurfaceContext(IOSurfaceRef surface, IntSize size, CGColorSpaceRef colorSpace)
+{
+ if (!surface)
+ return nullptr;
+
+ CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
+ size_t bitsPerComponent = 8;
+ size_t bitsPerPixel = 32;
+ return adoptCF(CGIOSurfaceContextCreate(surface, size.width(), size.height(), bitsPerComponent, bitsPerPixel, colorSpace, bitmapInfo));
+}
+
+static RetainPtr<IOSurfaceRef> createIOSurface(IntSize size)
+{
+ unsigned pixelFormat = 'BGRA';
+ unsigned bytesPerElement = 4;
+ int width = size.width();
+ int height = size.height();
+
+ unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
+ ASSERT(bytesPerRow);
+
+ unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
+ ASSERT(allocSize);
+
+ NSDictionary *dict = @{
+ (id)kIOSurfaceWidth: @(width),
+ (id)kIOSurfaceHeight: @(height),
+ (id)kIOSurfacePixelFormat: @(pixelFormat),
+ (id)kIOSurfaceBytesPerElement: @(bytesPerElement),
+ (id)kIOSurfaceBytesPerRow: @(bytesPerRow),
+ (id)kIOSurfaceAllocSize: @(allocSize)
+ };
+
+ return adoptCF(IOSurfaceCreate((CFDictionaryRef)dict));
+}
+
+RetainPtr<CGImageRef> RemoteLayerBackingStore::image() const
+{
+ if (!m_frontBuffer || m_acceleratesDrawing)
+ return nullptr;
+
+ // FIXME: Do we need Copy?
+ return m_frontBuffer->makeCGImageCopy();
+}
+
+bool RemoteLayerBackingStore::display()
+{
+ if (!m_layer)
+ return false;
+
+ // If we previously were drawsContent=YES, and now are not, we need
+ // to note that our backing store has been cleared.
+ if (!m_layer->owner() || !m_layer->owner()->platformCALayerDrawsContent()) {
+ bool previouslyDrewContents = hasFrontBuffer();
+
+ m_frontBuffer = nullptr;
+ m_frontSurface = nullptr;
+
+ return previouslyDrewContents;
+ }
+
+ if (!hasFrontBuffer())
+ m_dirtyRegion.unite(IntRect(IntPoint(), m_size));
+
+ if (m_dirtyRegion.isEmpty() || m_size.isEmpty())
+ return false;
+
+ if (m_layer->owner()->platformCALayerShowRepaintCounter(m_layer)) {
+ IntRect indicatorRect = mapToContentCoordinates(IntRect(0, 0, 52, 27));
+ m_dirtyRegion.unite(indicatorRect);
+ }
+
+ FloatSize scaledSize = m_size;
+ scaledSize.scale(m_scale);
+ IntSize expandedScaledSize = expandedIntSize(scaledSize);
+
+ std::unique_ptr<GraphicsContext> context;
+ RefPtr<ShareableBitmap> backBuffer;
+ RetainPtr<IOSurfaceRef> backSurface;
+
+ if (m_acceleratesDrawing) {
+ backSurface = createIOSurface(expandedScaledSize);
+ RetainPtr<CGContextRef> cgContext = createIOSurfaceContext(backSurface.get(), expandedScaledSize, sRGBColorSpaceRef());
+ context = std::make_unique<GraphicsContext>(cgContext.get());
+ CGContextClearRect(cgContext.get(), CGRectMake(0, 0, expandedScaledSize.width(), expandedScaledSize.height()));
+ context->scale(FloatSize(1, -1));
+ context->translate(0, -expandedScaledSize.height());
+ } else {
+ backBuffer = ShareableBitmap::createShareable(expandedIntSize(scaledSize), ShareableBitmap::SupportsAlpha);
+ context = backBuffer->createGraphicsContext();
+ }
+
+ drawInContext(*context);
+
+ if (m_acceleratesDrawing)
+ m_frontSurface = backSurface;
+ else
+ m_frontBuffer = backBuffer;
+
+ return true;
+}
+
+void RemoteLayerBackingStore::drawInContext(GraphicsContext& context)
+{
+ RetainPtr<CGImageRef> frontImage;
+ RetainPtr<CGContextRef> frontContext;
+
+ if (m_acceleratesDrawing) {
+ frontContext = createIOSurfaceContext(m_frontSurface.get(), expandedIntSize(m_size * m_scale), sRGBColorSpaceRef());
+ frontImage = adoptCF(CGIOSurfaceContextCreateImage(frontContext.get()));
+ } else
+ frontImage = image();
+
+ Vector<IntRect> dirtyRects = m_dirtyRegion.rects();
+
+ // If we have less than webLayerMaxRectsToPaint rects to paint and they cover less
+ // than webLayerWastedSpaceThreshold of the area, we'll do a partial repaint.
+
+ Vector<FloatRect, webLayerMaxRectsToPaint> rectsToPaint;
+ if (dirtyRects.size() <= webLayerMaxRectsToPaint && m_dirtyRegion.totalArea() <= webLayerWastedSpaceThreshold * m_size.width() * m_size.height()) {
+ // Copy over the parts of the front buffer that we're not going to repaint.
+ if (frontImage) {
+ Region cleanRegion(IntRect(IntPoint(), m_size));
+ cleanRegion.subtract(m_dirtyRegion);
+
+ for (const auto& rect : cleanRegion.rects()) {
+ FloatRect scaledRect = rect;
+ scaledRect.scale(m_scale);
+ FloatSize imageSize(CGImageGetWidth(frontImage.get()), CGImageGetHeight(frontImage.get()));
+ context.drawNativeImage(frontImage.get(), imageSize, ColorSpaceDeviceRGB, scaledRect, scaledRect);
+ }
+ }
+
+ for (const auto& rect : dirtyRects)
+ rectsToPaint.append(rect);
+ }
+
+ context.scale(FloatSize(m_scale, m_scale));
+
+ switch (m_layer->layerType()) {
+ case PlatformCALayer::LayerTypeSimpleLayer:
+ case PlatformCALayer::LayerTypeTiledBackingTileLayer:
+ if (rectsToPaint.isEmpty())
+ rectsToPaint.append(IntRect(IntPoint(), m_size));
+ for (const auto& rect : rectsToPaint)
+ m_layer->owner()->platformCALayerPaintContents(m_layer, context, enclosingIntRect(rect));
+ break;
+ case PlatformCALayer::LayerTypeWebLayer:
+ drawLayerContents(context.platformContext(), m_layer, rectsToPaint);
+ break;
+ case PlatformCALayer::LayerTypeLayer:
+ case PlatformCALayer::LayerTypeTransformLayer:
+ case PlatformCALayer::LayerTypeWebTiledLayer:
+ case PlatformCALayer::LayerTypeTiledBackingLayer:
+ case PlatformCALayer::LayerTypePageTiledBackingLayer:
+ case PlatformCALayer::LayerTypeRootLayer:
+ case PlatformCALayer::LayerTypeAVPlayerLayer:
+ case PlatformCALayer::LayerTypeCustom:
+ break;
+ };
+
+ m_dirtyRegion = Region();
+
+ CGContextFlush(context.platformContext());
+
+ // If our frontImage is derived from an IOSurface, we need to
+ // destroy the image before the CGContext it's derived from,
+ // so that the context doesn't make a CPU copy of the surface data.
+ frontImage = nullptr;
+ frontContext = nullptr;
+}
+
+#endif // USE(ACCELERATED_COMPOSITING)
Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (158462 => 158463)
--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2013-11-01 23:24:40 UTC (rev 158462)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj 2013-11-01 23:24:49 UTC (rev 158463)
@@ -4594,6 +4594,8 @@
BCF505E51243047B005955AE /* PlatformCertificateInfo.h */,
BCF505E61243047B005955AE /* PlatformCertificateInfo.mm */,
E1CC1B8F12D7EADF00625838 /* PrintInfoMac.mm */,
+ 2D47B56A1810714E003A3AEE /* RemoteLayerBackingStore.mm */,
+ 2D47B56B1810714E003A3AEE /* RemoteLayerBackingStore.h */,
1AF1AC6A1651759E00C17D7F /* RemoteLayerTreeTransaction.h */,
1AF1AC691651759E00C17D7F /* RemoteLayerTreeTransaction.mm */,
1AAB4AA91296F1540023952F /* SandboxExtensionMac.mm */,
@@ -4934,8 +4936,6 @@
2DA049B2180CCCD300AAFA9E /* PlatformCALayerRemote.h */,
2D8949EE182044F600E898AA /* PlatformCALayerRemoteTiledBacking.cpp */,
2D8949EF182044F600E898AA /* PlatformCALayerRemoteTiledBacking.h */,
- 2D47B56A1810714E003A3AEE /* RemoteLayerBackingStore.mm */,
- 2D47B56B1810714E003A3AEE /* RemoteLayerBackingStore.h */,
1AB16AE8164B3A8800290D62 /* RemoteLayerTreeContext.h */,
1AB16AE7164B3A8800290D62 /* RemoteLayerTreeContext.mm */,
1AB16ADC1648598400290D62 /* RemoteLayerTreeDrawingArea.h */,
Deleted: trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.h (158462 => 158463)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.h 2013-11-01 23:24:40 UTC (rev 158462)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.h 2013-11-01 23:24:49 UTC (rev 158463)
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef RemoteLayerBackingStore_h
-#define RemoteLayerBackingStore_h
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#include "ShareableBitmap.h"
-#include <WebCore/FloatRect.h>
-#include <WebCore/Region.h>
-
-namespace WebKit {
-
-class PlatformCALayerRemote;
-
-class RemoteLayerBackingStore {
-public:
- RemoteLayerBackingStore();
-
- void ensureBackingStore(PlatformCALayerRemote*, WebCore::IntSize, float scale, bool acceleratesDrawing);
-
- void setNeedsDisplay(const WebCore::IntRect);
- void setNeedsDisplay();
-
- bool display();
-
- RetainPtr<CGImageRef> image() const;
- RetainPtr<IOSurfaceRef> surface() const { return m_frontSurface; }
- WebCore::IntSize size() const { return m_size; }
- float scale() const { return m_scale; }
- bool acceleratesDrawing() const { return m_acceleratesDrawing; }
-
- PlatformCALayerRemote* layer() const { return m_layer; }
-
- void encode(CoreIPC::ArgumentEncoder&) const;
- static bool decode(CoreIPC::ArgumentDecoder&, RemoteLayerBackingStore&);
-
-private:
- WebCore::IntRect mapToContentCoordinates(const WebCore::IntRect) const;
-
- bool hasFrontBuffer() { return m_acceleratesDrawing ? !!m_frontSurface : !!m_frontBuffer; }
-
- std::unique_ptr<WebCore::GraphicsContext> createBackingStore();
- void drawInContext(WebCore::GraphicsContext&);
-
- PlatformCALayerRemote* m_layer;
-
- WebCore::IntSize m_size;
- float m_scale;
-
- WebCore::Region m_dirtyRegion;
-
- RefPtr<ShareableBitmap> m_frontBuffer;
- RetainPtr<IOSurfaceRef> m_frontSurface;
-
- bool m_acceleratesDrawing;
-};
-
-} // namespace WebKit
-
-#endif // USE(ACCELERATED_COMPOSITING)
-
-#endif // RemoteLayerBackingStore_h
Deleted: trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.mm (158462 => 158463)
--- trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.mm 2013-11-01 23:24:40 UTC (rev 158462)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerBackingStore.mm 2013-11-01 23:24:49 UTC (rev 158463)
@@ -1,306 +0,0 @@
- /*
- * Copyright (C) 2013 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#import "config.h"
-#import "RemoteLayerBackingStore.h"
-
-#if USE(ACCELERATED_COMPOSITING)
-
-#import "ArgumentCoders.h"
-#import "MachPort.h"
-#import "PlatformCALayerRemote.h"
-#import "ShareableBitmap.h"
-#import "WebCoreArgumentCoders.h"
-#import <WebCore/GraphicsContextCG.h>
-#import <WebCore/WebLayer.h>
-
-#ifdef __has_include
-#if __has_include(<ApplicationServices/ApplicationServicesPriv.h>)
-#import <ApplicationServices/ApplicationServicesPriv.h>
-#endif
-#endif
-
-extern "C" {
-CGContextRef CGIOSurfaceContextCreate(IOSurfaceRef, size_t, size_t, size_t, size_t, CGColorSpaceRef, CGBitmapInfo);
-CGImageRef CGIOSurfaceContextCreateImage(CGContextRef);
-}
-
-using namespace WebCore;
-using namespace WebKit;
-
-RemoteLayerBackingStore::RemoteLayerBackingStore()
- : m_layer(nullptr)
-{
-}
-
-void RemoteLayerBackingStore::ensureBackingStore(PlatformCALayerRemote* layer, IntSize size, float scale, bool acceleratesDrawing)
-{
- if (m_layer == layer && m_size == size && m_scale == scale && m_acceleratesDrawing == acceleratesDrawing)
- return;
-
- m_layer = layer;
- m_size = size;
- m_scale = scale;
- m_acceleratesDrawing = acceleratesDrawing;
-
- m_frontSurface = nullptr;
- m_frontBuffer = nullptr;
-}
-
-void RemoteLayerBackingStore::encode(CoreIPC::ArgumentEncoder& encoder) const
-{
- encoder << m_size;
- encoder << m_scale;
- encoder << m_acceleratesDrawing;
-
- if (m_acceleratesDrawing) {
- mach_port_t port = IOSurfaceCreateMachPort(m_frontSurface.get());
- encoder << CoreIPC::MachPort(port, MACH_MSG_TYPE_MOVE_SEND);
- } else {
- ShareableBitmap::Handle handle;
- m_frontBuffer->createHandle(handle);
- encoder << handle;
- }
-}
-
-bool RemoteLayerBackingStore::decode(CoreIPC::ArgumentDecoder& decoder, RemoteLayerBackingStore& result)
-{
- if (!decoder.decode(result.m_size))
- return false;
-
- if (!decoder.decode(result.m_scale))
- return false;
-
- if (!decoder.decode(result.m_acceleratesDrawing))
- return false;
-
- if (result.m_acceleratesDrawing) {
- CoreIPC::MachPort machPort;
- if (!decoder.decode(machPort))
- return false;
- result.m_frontSurface = adoptCF(IOSurfaceLookupFromMachPort(machPort.port()));
- mach_port_deallocate(mach_task_self(), machPort.port());
- } else {
- ShareableBitmap::Handle handle;
- if (!decoder.decode(handle))
- return false;
- result.m_frontBuffer = ShareableBitmap::create(handle);
- }
-
- return true;
-}
-
-IntRect RemoteLayerBackingStore::mapToContentCoordinates(const IntRect rect) const
-{
- IntRect flippedRect = rect;
- if (m_layer->owner()->platformCALayerContentsOrientation() == GraphicsLayer::CompositingCoordinatesBottomUp)
- flippedRect.setY(m_size.height() - rect.y() - rect.height());
- return flippedRect;
-}
-
-void RemoteLayerBackingStore::setNeedsDisplay(const IntRect rect)
-{
- IntRect flippedRect = mapToContentCoordinates(rect);
- m_dirtyRegion.unite(flippedRect);
-}
-
-void RemoteLayerBackingStore::setNeedsDisplay()
-{
- setNeedsDisplay(IntRect(IntPoint(), m_size));
-}
-
-static RetainPtr<CGContextRef> createIOSurfaceContext(IOSurfaceRef surface, IntSize size, CGColorSpaceRef colorSpace)
-{
- if (!surface)
- return nullptr;
-
- CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host;
- size_t bitsPerComponent = 8;
- size_t bitsPerPixel = 32;
- return adoptCF(CGIOSurfaceContextCreate(surface, size.width(), size.height(), bitsPerComponent, bitsPerPixel, colorSpace, bitmapInfo));
-}
-
-static RetainPtr<IOSurfaceRef> createIOSurface(IntSize size)
-{
- unsigned pixelFormat = 'BGRA';
- unsigned bytesPerElement = 4;
- int width = size.width();
- int height = size.height();
-
- unsigned long bytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, width * bytesPerElement);
- ASSERT(bytesPerRow);
-
- unsigned long allocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, height * bytesPerRow);
- ASSERT(allocSize);
-
- NSDictionary *dict = @{
- (id)kIOSurfaceWidth: @(width),
- (id)kIOSurfaceHeight: @(height),
- (id)kIOSurfacePixelFormat: @(pixelFormat),
- (id)kIOSurfaceBytesPerElement: @(bytesPerElement),
- (id)kIOSurfaceBytesPerRow: @(bytesPerRow),
- (id)kIOSurfaceAllocSize: @(allocSize)
- };
-
- return adoptCF(IOSurfaceCreate((CFDictionaryRef)dict));
-}
-
-RetainPtr<CGImageRef> RemoteLayerBackingStore::image() const
-{
- if (!m_frontBuffer || m_acceleratesDrawing)
- return nullptr;
-
- // FIXME: Do we need Copy?
- return m_frontBuffer->makeCGImageCopy();
-}
-
-bool RemoteLayerBackingStore::display()
-{
- if (!m_layer)
- return false;
-
- // If we previously were drawsContent=YES, and now are not, we need
- // to note that our backing store has been cleared.
- if (!m_layer->owner() || !m_layer->owner()->platformCALayerDrawsContent()) {
- bool previouslyDrewContents = hasFrontBuffer();
-
- m_frontBuffer = nullptr;
- m_frontSurface = nullptr;
-
- return previouslyDrewContents;
- }
-
- if (!hasFrontBuffer())
- m_dirtyRegion.unite(IntRect(IntPoint(), m_size));
-
- if (m_dirtyRegion.isEmpty() || m_size.isEmpty())
- return false;
-
- if (m_layer->owner()->platformCALayerShowRepaintCounter(m_layer)) {
- IntRect indicatorRect = mapToContentCoordinates(IntRect(0, 0, 52, 27));
- m_dirtyRegion.unite(indicatorRect);
- }
-
- FloatSize scaledSize = m_size;
- scaledSize.scale(m_scale);
- IntSize expandedScaledSize = expandedIntSize(scaledSize);
-
- std::unique_ptr<GraphicsContext> context;
- RefPtr<ShareableBitmap> backBuffer;
- RetainPtr<IOSurfaceRef> backSurface;
-
- if (m_acceleratesDrawing) {
- backSurface = createIOSurface(expandedScaledSize);
- RetainPtr<CGContextRef> cgContext = createIOSurfaceContext(backSurface.get(), expandedScaledSize, sRGBColorSpaceRef());
- context = std::make_unique<GraphicsContext>(cgContext.get());
- CGContextClearRect(cgContext.get(), CGRectMake(0, 0, expandedScaledSize.width(), expandedScaledSize.height()));
- context->scale(FloatSize(1, -1));
- context->translate(0, -expandedScaledSize.height());
- } else {
- backBuffer = ShareableBitmap::createShareable(expandedIntSize(scaledSize), ShareableBitmap::SupportsAlpha);
- context = backBuffer->createGraphicsContext();
- }
-
- drawInContext(*context);
-
- if (m_acceleratesDrawing)
- m_frontSurface = backSurface;
- else
- m_frontBuffer = backBuffer;
-
- return true;
-}
-
-void RemoteLayerBackingStore::drawInContext(GraphicsContext& context)
-{
- RetainPtr<CGImageRef> frontImage;
- RetainPtr<CGContextRef> frontContext;
-
- if (m_acceleratesDrawing) {
- frontContext = createIOSurfaceContext(m_frontSurface.get(), expandedIntSize(m_size * m_scale), sRGBColorSpaceRef());
- frontImage = adoptCF(CGIOSurfaceContextCreateImage(frontContext.get()));
- } else
- frontImage = image();
-
- Vector<IntRect> dirtyRects = m_dirtyRegion.rects();
-
- // If we have less than webLayerMaxRectsToPaint rects to paint and they cover less
- // than webLayerWastedSpaceThreshold of the area, we'll do a partial repaint.
-
- Vector<FloatRect, webLayerMaxRectsToPaint> rectsToPaint;
- if (dirtyRects.size() <= webLayerMaxRectsToPaint && m_dirtyRegion.totalArea() <= webLayerWastedSpaceThreshold * m_size.width() * m_size.height()) {
- // Copy over the parts of the front buffer that we're not going to repaint.
- if (frontImage) {
- Region cleanRegion(IntRect(IntPoint(), m_size));
- cleanRegion.subtract(m_dirtyRegion);
-
- for (const auto& rect : cleanRegion.rects()) {
- FloatRect scaledRect = rect;
- scaledRect.scale(m_scale);
- FloatSize imageSize(CGImageGetWidth(frontImage.get()), CGImageGetHeight(frontImage.get()));
- context.drawNativeImage(frontImage.get(), imageSize, ColorSpaceDeviceRGB, scaledRect, scaledRect);
- }
- }
-
- for (const auto& rect : dirtyRects)
- rectsToPaint.append(rect);
- }
-
- context.scale(FloatSize(m_scale, m_scale));
-
- switch (m_layer->layerType()) {
- case PlatformCALayer::LayerTypeSimpleLayer:
- case PlatformCALayer::LayerTypeTiledBackingTileLayer:
- if (rectsToPaint.isEmpty())
- rectsToPaint.append(IntRect(IntPoint(), m_size));
- for (const auto& rect : rectsToPaint)
- m_layer->owner()->platformCALayerPaintContents(m_layer, context, enclosingIntRect(rect));
- break;
- case PlatformCALayer::LayerTypeWebLayer:
- drawLayerContents(context.platformContext(), m_layer, rectsToPaint);
- break;
- case PlatformCALayer::LayerTypeLayer:
- case PlatformCALayer::LayerTypeTransformLayer:
- case PlatformCALayer::LayerTypeWebTiledLayer:
- case PlatformCALayer::LayerTypeTiledBackingLayer:
- case PlatformCALayer::LayerTypePageTiledBackingLayer:
- case PlatformCALayer::LayerTypeRootLayer:
- case PlatformCALayer::LayerTypeAVPlayerLayer:
- case PlatformCALayer::LayerTypeCustom:
- break;
- };
-
- m_dirtyRegion = Region();
-
- CGContextFlush(context.platformContext());
-
- // If our frontImage is derived from an IOSurface, we need to
- // destroy the image before the CGContext it's derived from,
- // so that the context doesn't make a CPU copy of the surface data.
- frontImage = nullptr;
- frontContext = nullptr;
-}
-
-#endif // USE(ACCELERATED_COMPOSITING)