diff options
author | Ben Murdoch <benm@google.com> | 2011-05-13 16:23:25 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-16 11:35:02 +0100 |
commit | 65f03d4f644ce73618e5f4f50dd694b26f55ae12 (patch) | |
tree | f478babb801e720de7bfaee23443ffe029f58731 /Source/WebCore/platform/graphics/win | |
parent | 47de4a2fb7262c7ebdb9cd133ad2c54c187454d0 (diff) | |
download | external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.zip external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.gz external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.bz2 |
Merge WebKit at r75993: Initial merge by git.
Change-Id: I602bbdc3974787a3b0450456a30a7868286921c3
Diffstat (limited to 'Source/WebCore/platform/graphics/win')
5 files changed, 36 insertions, 926 deletions
diff --git a/Source/WebCore/platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp b/Source/WebCore/platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp index cbe38aa..7abe2eb 100644 --- a/Source/WebCore/platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp +++ b/Source/WebCore/platform/graphics/win/MediaPlayerPrivateFullscreenWindow.cpp @@ -80,6 +80,10 @@ void MediaPlayerPrivateFullscreenWindow::createWindow(HWND parentHwnd) parentHwnd, 0, WebCore::instanceHandle(), this); ASSERT(IsWindow(m_hwnd)); +#if USE(ACCELERATED_COMPOSITING) + m_layerRenderer->setHostWindow(m_hwnd); +#endif + ::SetFocus(m_hwnd); } @@ -139,17 +143,10 @@ LRESULT MediaPlayerPrivateFullscreenWindow::wndProc(HWND hWnd, UINT message, WPA switch (message) { case WM_CREATE: m_hwnd = hWnd; -#if USE(ACCELERATED_COMPOSITING) - m_layerRenderer->setHostWindow(m_hwnd); - m_layerRenderer->createRenderer(); - if (m_rootChild) - m_layerRenderer->setNeedsDisplay(); -#endif break; case WM_DESTROY: m_hwnd = 0; #if USE(ACCELERATED_COMPOSITING) - m_layerRenderer->destroyRenderer(); m_layerRenderer->setHostWindow(0); #endif break; @@ -169,7 +166,8 @@ LRESULT MediaPlayerPrivateFullscreenWindow::wndProc(HWND hWnd, UINT message, WPA break; case WM_PAINT: #if USE(ACCELERATED_COMPOSITING) - m_layerRenderer->renderSoon(); + m_layerRenderer->paint(); + ::ValidateRect(m_hwnd, 0); #endif break; } diff --git a/Source/WebCore/platform/graphics/win/WKCACFLayer.cpp b/Source/WebCore/platform/graphics/win/WKCACFLayer.cpp deleted file mode 100644 index a8714e3..0000000 --- a/Source/WebCore/platform/graphics/win/WKCACFLayer.cpp +++ /dev/null @@ -1,572 +0,0 @@ -/* - * Copyright (C) 2009 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. - */ - -#include "config.h" - -#if USE(ACCELERATED_COMPOSITING) - -#include "WKCACFLayer.h" - -#include "WKCACFLayerRenderer.h" -#include <WebKitSystemInterface/WebKitSystemInterface.h> -#include <stdio.h> -#include <wtf/CurrentTime.h> -#include <wtf/text/CString.h> - -namespace WebCore { - -using namespace std; - -#ifndef NDEBUG -void WKCACFLayer::internalCheckLayerConsistency() -{ - ASSERT(layer()); - size_t n = sublayerCount(); - for (size_t i = 0; i < n; ++i) { - // This will ASSERT in internalSublayerAtIndex if this entry doesn't have proper user data - WKCACFLayer* sublayer = internalSublayerAtIndex(i); - - // Make sure we don't have any null entries in the list - ASSERT(sublayer); - - // Make sure the each layer has a corresponding CACFLayer - ASSERT(sublayer->layer()); - } -} -#endif - -static void displayCallback(CACFLayerRef layer, CGContextRef context) -{ - ASSERT_ARG(layer, WKCACFLayer::layer(layer)); - WKCACFLayer::layer(layer)->drawInContext(context); -} - -static CFStringRef toCACFLayerType(WKCACFLayer::LayerType type) -{ - switch (type) { - case WKCACFLayer::Layer: return kCACFLayer; - case WKCACFLayer::TransformLayer: return kCACFTransformLayer; - default: return 0; - } -} - -static CFStringRef toCACFContentsGravityType(WKCACFLayer::ContentsGravityType type) -{ - switch (type) { - case WKCACFLayer::Center: return kCACFGravityCenter; - case WKCACFLayer::Top: return kCACFGravityTop; - case WKCACFLayer::Bottom: return kCACFGravityBottom; - case WKCACFLayer::Left: return kCACFGravityLeft; - case WKCACFLayer::Right: return kCACFGravityRight; - case WKCACFLayer::TopLeft: return kCACFGravityTopLeft; - case WKCACFLayer::TopRight: return kCACFGravityTopRight; - case WKCACFLayer::BottomLeft: return kCACFGravityBottomLeft; - case WKCACFLayer::BottomRight: return kCACFGravityBottomRight; - case WKCACFLayer::Resize: return kCACFGravityResize; - case WKCACFLayer::ResizeAspect: return kCACFGravityResizeAspect; - case WKCACFLayer::ResizeAspectFill: return kCACFGravityResizeAspectFill; - default: return 0; - } -} - -static WKCACFLayer::ContentsGravityType fromCACFContentsGravityType(CFStringRef string) -{ - if (CFEqual(string, kCACFGravityTop)) - return WKCACFLayer::Top; - - if (CFEqual(string, kCACFGravityBottom)) - return WKCACFLayer::Bottom; - - if (CFEqual(string, kCACFGravityLeft)) - return WKCACFLayer::Left; - - if (CFEqual(string, kCACFGravityRight)) - return WKCACFLayer::Right; - - if (CFEqual(string, kCACFGravityTopLeft)) - return WKCACFLayer::TopLeft; - - if (CFEqual(string, kCACFGravityTopRight)) - return WKCACFLayer::TopRight; - - if (CFEqual(string, kCACFGravityBottomLeft)) - return WKCACFLayer::BottomLeft; - - if (CFEqual(string, kCACFGravityBottomRight)) - return WKCACFLayer::BottomRight; - - if (CFEqual(string, kCACFGravityResize)) - return WKCACFLayer::Resize; - - if (CFEqual(string, kCACFGravityResizeAspect)) - return WKCACFLayer::ResizeAspect; - - if (CFEqual(string, kCACFGravityResizeAspectFill)) - return WKCACFLayer::ResizeAspectFill; - - return WKCACFLayer::Center; -} - -static CFStringRef toCACFFilterType(WKCACFLayer::FilterType type) -{ - switch (type) { - case WKCACFLayer::Linear: return kCACFFilterLinear; - case WKCACFLayer::Nearest: return kCACFFilterNearest; - case WKCACFLayer::Trilinear: return kCACFFilterTrilinear; - default: return 0; - } -} - -static WKCACFLayer::FilterType fromCACFFilterType(CFStringRef string) -{ - if (CFEqual(string, kCACFFilterNearest)) - return WKCACFLayer::Nearest; - - if (CFEqual(string, kCACFFilterTrilinear)) - return WKCACFLayer::Trilinear; - - return WKCACFLayer::Linear; -} - -PassRefPtr<WKCACFLayer> WKCACFLayer::create(LayerType type) -{ - if (!WKCACFLayerRenderer::acceleratedCompositingAvailable()) - return 0; - return adoptRef(new WKCACFLayer(type)); -} - -// FIXME: It might be good to have a way of ensuring that all WKCACFLayers eventually -// get destroyed in debug builds. A static counter could accomplish this pretty easily. - -WKCACFLayer::WKCACFLayer(LayerType type) - : m_layer(AdoptCF, CACFLayerCreate(toCACFLayerType(type))) - , m_layoutClient(0) - , m_needsDisplayOnBoundsChange(false) -{ - CACFLayerSetUserData(layer(), this); - CACFLayerSetDisplayCallback(layer(), displayCallback); -} - -WKCACFLayer::~WKCACFLayer() -{ - // Our superlayer should be holding a reference to us, so there should be no way for us to be destroyed while we still have a superlayer. - ASSERT(!superlayer()); - - // Get rid of the children so we don't have any dangling references around - removeAllSublayers(); - -#ifndef NDEBUG - CACFLayerSetUserData(layer(), reinterpret_cast<void*>(0xDEADBEEF)); -#else - CACFLayerSetUserData(layer(), 0); -#endif - CACFLayerSetDisplayCallback(layer(), 0); -} - -void WKCACFLayer::becomeRootLayerForContext(WKCACFContext* context) -{ - wkCACFContextSetLayer(context, layer()); - setNeedsCommit(); -} - -void WKCACFLayer::setNeedsCommit() -{ - WKCACFLayer* root = rootLayer(); - - // Call setNeedsRender on the root layer, which will cause a render to - // happen in WKCACFLayerRenderer - root->setNeedsRender(); -} - -bool WKCACFLayer::isTransformLayer() const -{ - return CACFLayerGetClass(layer()) == kCACFTransformLayer; -} - -void WKCACFLayer::addSublayer(PassRefPtr<WKCACFLayer> sublayer) -{ - insertSublayer(sublayer, sublayerCount()); -} - -void WKCACFLayer::internalInsertSublayer(PassRefPtr<WKCACFLayer> sublayer, size_t index) -{ - index = min(index, sublayerCount() + 1); - sublayer->removeFromSuperlayer(); - CACFLayerInsertSublayer(layer(), sublayer->layer(), index); - setNeedsCommit(); - checkLayerConsistency(); -} - -void WKCACFLayer::insertSublayerAboveLayer(PassRefPtr<WKCACFLayer> sublayer, const WKCACFLayer* reference) -{ - if (!reference) { - insertSublayer(sublayer, 0); - return; - } - - int referenceIndex = internalIndexOfSublayer(reference); - if (referenceIndex == -1) { - addSublayer(sublayer); - return; - } - - insertSublayer(sublayer, referenceIndex + 1); -} - -void WKCACFLayer::insertSublayerBelowLayer(PassRefPtr<WKCACFLayer> sublayer, const WKCACFLayer* reference) -{ - if (!reference) { - insertSublayer(sublayer, 0); - return; - } - - int referenceIndex = internalIndexOfSublayer(reference); - if (referenceIndex == -1) { - addSublayer(sublayer); - return; - } - - insertSublayer(sublayer, referenceIndex); -} - -void WKCACFLayer::replaceSublayer(WKCACFLayer* reference, PassRefPtr<WKCACFLayer> newLayer) -{ - ASSERT_ARG(reference, reference); - ASSERT_ARG(reference, reference->superlayer() == this); - - if (reference == newLayer) - return; - - int referenceIndex = internalIndexOfSublayer(reference); - ASSERT(referenceIndex != -1); - if (referenceIndex == -1) - return; - - reference->removeFromSuperlayer(); - - if (newLayer) { - newLayer->removeFromSuperlayer(); - insertSublayer(newLayer, referenceIndex); - } -} - -size_t WKCACFLayer::internalSublayerCount() const -{ - CFArrayRef sublayers = CACFLayerGetSublayers(layer()); - return sublayers ? CFArrayGetCount(sublayers) : 0; -} - -void WKCACFLayer::adoptSublayers(WKCACFLayer* source) -{ - // We will use setSublayers() because it properly nulls - // out the superlayer pointer. - Vector<RefPtr<WKCACFLayer> > sublayers; - size_t n = source->sublayerCount(); - - for (size_t i = 0; i < n; ++i) - sublayers.append(source->internalSublayerAtIndex(i)); - - setSublayers(sublayers); - source->checkLayerConsistency(); -} - -void WKCACFLayer::removeFromSuperlayer() -{ - WKCACFLayer* superlayer = this->superlayer(); - CACFLayerRemoveFromSuperlayer(layer()); - checkLayerConsistency(); - - if (superlayer) - superlayer->setNeedsCommit(); -} - -WKCACFLayer* WKCACFLayer::internalSublayerAtIndex(int index) const -{ - CFArrayRef sublayers = CACFLayerGetSublayers(layer()); - if (!sublayers || index < 0 || CFArrayGetCount(sublayers) <= index) - return 0; - - return layer(static_cast<CACFLayerRef>(const_cast<void*>(CFArrayGetValueAtIndex(sublayers, index)))); -} - -int WKCACFLayer::internalIndexOfSublayer(const WKCACFLayer* reference) -{ - CACFLayerRef ref = reference->layer(); - if (!ref) - return -1; - - CFArrayRef sublayers = CACFLayerGetSublayers(layer()); - if (!sublayers) - return -1; - - size_t n = CFArrayGetCount(sublayers); - - for (size_t i = 0; i < n; ++i) - if (CFArrayGetValueAtIndex(sublayers, i) == ref) - return i; - - return -1; -} - -WKCACFLayer* WKCACFLayer::ancestorOrSelfWithSuperlayer(WKCACFLayer* superlayer) const -{ - WKCACFLayer* layer = const_cast<WKCACFLayer*>(this); - for (WKCACFLayer* ancestor = this->superlayer(); ancestor; layer = ancestor, ancestor = ancestor->superlayer()) { - if (ancestor == superlayer) - return layer; - } - return 0; -} - -void WKCACFLayer::setBounds(const CGRect& rect) -{ - if (CGRectEqualToRect(rect, bounds())) - return; - - CACFLayerSetBounds(layer(), rect); - setNeedsCommit(); - - if (m_needsDisplayOnBoundsChange) - setNeedsDisplay(); - - if (m_layoutClient) - setNeedsLayout(); -} - -void WKCACFLayer::setFrame(const CGRect& rect) -{ - CGRect oldFrame = frame(); - if (CGRectEqualToRect(rect, oldFrame)) - return; - - CACFLayerSetFrame(layer(), rect); - setNeedsCommit(); - - if (m_needsDisplayOnBoundsChange && !CGSizeEqualToSize(rect.size, oldFrame.size)) - setNeedsDisplay(); - - if (m_layoutClient) - setNeedsLayout(); -} - -void WKCACFLayer::setContentsGravity(ContentsGravityType type) -{ - CACFLayerSetContentsGravity(layer(), toCACFContentsGravityType(type)); - setNeedsCommit(); -} - -WKCACFLayer::ContentsGravityType WKCACFLayer::contentsGravity() const -{ - return fromCACFContentsGravityType(CACFLayerGetContentsGravity(layer())); -} - -void WKCACFLayer::setMagnificationFilter(FilterType type) -{ - CACFLayerSetMagnificationFilter(layer(), toCACFFilterType(type)); - setNeedsCommit(); -} - -WKCACFLayer::FilterType WKCACFLayer::magnificationFilter() const -{ - return fromCACFFilterType(CACFLayerGetMagnificationFilter(layer())); -} - -void WKCACFLayer::setMinificationFilter(FilterType type) -{ - CACFLayerSetMinificationFilter(layer(), toCACFFilterType(type)); - setNeedsCommit(); -} - -WKCACFLayer::FilterType WKCACFLayer::minificationFilter() const -{ - return fromCACFFilterType(CACFLayerGetMinificationFilter(layer())); -} - -WKCACFLayer* WKCACFLayer::rootLayer() const -{ - WKCACFLayer* layer = const_cast<WKCACFLayer*>(this); - for (WKCACFLayer* superlayer = layer->superlayer(); superlayer; layer = superlayer, superlayer = superlayer->superlayer()) { } - return layer; -} - -void WKCACFLayer::internalRemoveAllSublayers() -{ - CACFLayerSetSublayers(layer(), 0); - setNeedsCommit(); -} - -void WKCACFLayer::internalSetSublayers(const Vector<RefPtr<WKCACFLayer> >& sublayers) -{ - // Remove all the current sublayers and add the passed layers - CACFLayerSetSublayers(layer(), 0); - - // Perform removeFromSuperLayer in a separate pass. CACF requires superlayer to - // be null or CACFLayerInsertSublayer silently fails. - for (size_t i = 0; i < sublayers.size(); i++) - CACFLayerRemoveFromSuperlayer(sublayers[i]->layer()); - - for (size_t i = 0; i < sublayers.size(); i++) - CACFLayerInsertSublayer(layer(), sublayers[i]->layer(), i); - - setNeedsCommit(); -} - -WKCACFLayer* WKCACFLayer::superlayer() const -{ - CACFLayerRef super = CACFLayerGetSuperlayer(layer()); - if (!super) - return 0; - return WKCACFLayer::layer(super); -} - -void WKCACFLayer::internalSetNeedsDisplay(const CGRect* dirtyRect) -{ - CACFLayerSetNeedsDisplay(layer(), dirtyRect); -} - -void WKCACFLayer::setLayoutClient(WKCACFLayerLayoutClient* layoutClient) -{ - if (layoutClient == m_layoutClient) - return; - - m_layoutClient = layoutClient; - CACFLayerSetLayoutCallback(layer(), m_layoutClient ? layoutSublayersProc : 0); -} - -void WKCACFLayer::layoutSublayersProc(CACFLayerRef caLayer) -{ - WKCACFLayer* layer = WKCACFLayer::layer(caLayer); - if (layer && layer->m_layoutClient) - layer->m_layoutClient->layoutSublayersOfLayer(layer); -} - -#ifndef NDEBUG -static void printIndent(int indent) -{ - for ( ; indent > 0; --indent) - fprintf(stderr, " "); -} - -static void printTransform(const CATransform3D& transform) -{ - fprintf(stderr, "[%g %g %g %g; %g %g %g %g; %g %g %g %g; %g %g %g %g]", - transform.m11, transform.m12, transform.m13, transform.m14, - transform.m21, transform.m22, transform.m23, transform.m24, - transform.m31, transform.m32, transform.m33, transform.m34, - transform.m41, transform.m42, transform.m43, transform.m44); -} - -void WKCACFLayer::printTree() const -{ - // Print heading info - CGRect rootBounds = bounds(); - fprintf(stderr, "\n\n** Render tree at time %g (bounds %g, %g %gx%g) **\n\n", - currentTime(), rootBounds.origin.x, rootBounds.origin.y, rootBounds.size.width, rootBounds.size.height); - - // Print layer tree from the root - printLayer(0); -} - -void WKCACFLayer::printLayer(int indent) const -{ - CGPoint layerPosition = position(); - CGPoint layerAnchorPoint = anchorPoint(); - CGRect layerBounds = bounds(); - printIndent(indent); - fprintf(stderr, "(%s [%g %g %g] [%g %g %g %g] [%g %g %g] superlayer=%p\n", - isTransformLayer() ? "transform-layer" : "layer", - layerPosition.x, layerPosition.y, zPosition(), - layerBounds.origin.x, layerBounds.origin.y, layerBounds.size.width, layerBounds.size.height, - layerAnchorPoint.x, layerAnchorPoint.y, anchorPointZ(), superlayer()); - - // Print name if needed - String layerName = name(); - if (!layerName.isEmpty()) { - printIndent(indent + 1); - fprintf(stderr, "(name %s)\n", layerName.utf8().data()); - } - - // Print masksToBounds if needed - bool layerMasksToBounds = masksToBounds(); - if (layerMasksToBounds) { - printIndent(indent + 1); - fprintf(stderr, "(masksToBounds true)\n"); - } - - // Print opacity if needed - float layerOpacity = opacity(); - if (layerOpacity != 1) { - printIndent(indent + 1); - fprintf(stderr, "(opacity %hf)\n", layerOpacity); - } - - // Print sublayerTransform if needed - CATransform3D layerTransform = sublayerTransform(); - if (!CATransform3DIsIdentity(layerTransform)) { - printIndent(indent + 1); - fprintf(stderr, "(sublayerTransform "); - printTransform(layerTransform); - fprintf(stderr, ")\n"); - } - - // Print transform if needed - layerTransform = transform(); - if (!CATransform3DIsIdentity(layerTransform)) { - printIndent(indent + 1); - fprintf(stderr, "(transform "); - printTransform(layerTransform); - fprintf(stderr, ")\n"); - } - - // Print contents if needed - CFTypeRef layerContents = contents(); - if (layerContents) { - if (CFGetTypeID(layerContents) == CGImageGetTypeID()) { - CGImageRef imageContents = static_cast<CGImageRef>(const_cast<void*>(layerContents)); - printIndent(indent + 1); - fprintf(stderr, "(contents (image [%d %d]))\n", - CGImageGetWidth(imageContents), CGImageGetHeight(imageContents)); - } - } - - // Print sublayers if needed - int n = sublayerCount(); - if (n > 0) { - printIndent(indent + 1); - fprintf(stderr, "(sublayers\n"); - for (int i = 0; i < n; ++i) - internalSublayerAtIndex(i)->printLayer(indent + 2); - - printIndent(indent + 1); - fprintf(stderr, ")\n"); - } - - printIndent(indent); - fprintf(stderr, ")\n"); -} -#endif // #ifndef NDEBUG -} - -#endif // USE(ACCELERATED_COMPOSITING) diff --git a/Source/WebCore/platform/graphics/win/WKCACFLayer.h b/Source/WebCore/platform/graphics/win/WKCACFLayer.h deleted file mode 100644 index 4c6639a..0000000 --- a/Source/WebCore/platform/graphics/win/WKCACFLayer.h +++ /dev/null @@ -1,299 +0,0 @@ -/* - * Copyright (C) 2009 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 WKCACFLayer_h -#define WKCACFLayer_h - -#if USE(ACCELERATED_COMPOSITING) - -#include <wtf/RefCounted.h> - -#include <QuartzCore/CACFLayer.h> -#include <QuartzCore/CACFVector.h> -#include <wtf/PassRefPtr.h> -#include <wtf/RetainPtr.h> -#include <wtf/Vector.h> -#include <wtf/text/StringHash.h> - -#include "GraphicsContext.h" -#include "PlatformString.h" -#include "TransformationMatrix.h" - -struct WKCACFContext; - -namespace WebCore { - -class WKCACFLayer; - -class WKCACFLayerLayoutClient { -public: - virtual void layoutSublayersOfLayer(WKCACFLayer*) = 0; -protected: - virtual ~WKCACFLayerLayoutClient() {} -}; - -class WKCACFLayer : public RefCounted<WKCACFLayer> { -public: - enum LayerType { Layer, TransformLayer }; - enum FilterType { Linear, Nearest, Trilinear }; - enum ContentsGravityType { Center, Top, Bottom, Left, Right, TopLeft, TopRight, - BottomLeft, BottomRight, Resize, ResizeAspect, ResizeAspectFill }; - - static PassRefPtr<WKCACFLayer> create(LayerType); - static WKCACFLayer* layer(CACFLayerRef layer) - { - ASSERT(CACFLayerGetUserData(layer) != reinterpret_cast<void*>(0xDEADBEEF)); - return static_cast<WKCACFLayer*>(CACFLayerGetUserData(layer)); - } - - virtual ~WKCACFLayer(); - - virtual void setNeedsRender() { } - - virtual void drawInContext(PlatformGraphicsContext*) { } - - void setLayoutClient(WKCACFLayerLayoutClient*); - WKCACFLayerLayoutClient* layoutClient() const { return m_layoutClient; } - void setNeedsLayout() { CACFLayerSetNeedsLayout(layer()); } - - void setNeedsDisplay(const CGRect* dirtyRect = 0) - { - internalSetNeedsDisplay(dirtyRect); - setNeedsCommit(); - } - - // Makes this layer the root when the passed context is rendered - void becomeRootLayerForContext(WKCACFContext*); - - static RetainPtr<CFTypeRef> cfValue(float value) { return RetainPtr<CFTypeRef>(AdoptCF, CFNumberCreate(0, kCFNumberFloat32Type, &value)); } - static RetainPtr<CFTypeRef> cfValue(const TransformationMatrix& value) - { - CATransform3D t; - t.m11 = value.m11(); - t.m12 = value.m12(); - t.m13 = value.m13(); - t.m14 = value.m14(); - t.m21 = value.m21(); - t.m22 = value.m22(); - t.m23 = value.m23(); - t.m24 = value.m24(); - t.m31 = value.m31(); - t.m32 = value.m32(); - t.m33 = value.m33(); - t.m34 = value.m34(); - t.m41 = value.m41(); - t.m42 = value.m42(); - t.m43 = value.m43(); - t.m44 = value.m44(); - return RetainPtr<CFTypeRef>(AdoptCF, CACFVectorCreateTransform(t)); - } - static RetainPtr<CFTypeRef> cfValue(const FloatPoint& value) - { - CGPoint p; - p.x = value.x(); p.y = value.y(); - return RetainPtr<CFTypeRef>(AdoptCF, CACFVectorCreatePoint(p)); - } - static RetainPtr<CFTypeRef> cfValue(const FloatRect& rect) - { - CGRect r; - r.origin.x = rect.x(); - r.origin.y = rect.y(); - r.size.width = rect.width(); - r.size.height = rect.height(); - CGFloat v[4] = { CGRectGetMinX(r), CGRectGetMinY(r), CGRectGetMaxX(r), CGRectGetMaxY(r) }; - return RetainPtr<CFTypeRef>(AdoptCF, CACFVectorCreate(4, v)); - } - static RetainPtr<CFTypeRef> cfValue(const Color& color) - { - return RetainPtr<CFTypeRef>(AdoptCF, CGColorCreateGenericRGB(color.red(), color.green(), color.blue(), color.alpha())); - } - - bool isTransformLayer() const; - - void addSublayer(PassRefPtr<WKCACFLayer> sublayer); - void insertSublayerAboveLayer(PassRefPtr<WKCACFLayer>, const WKCACFLayer* reference); - void insertSublayerBelowLayer(PassRefPtr<WKCACFLayer>, const WKCACFLayer* reference); - void replaceSublayer(WKCACFLayer* reference, PassRefPtr<WKCACFLayer>); - void adoptSublayers(WKCACFLayer* source); - - void removeAllSublayers() { internalRemoveAllSublayers(); } - void setSublayers(const Vector<RefPtr<WKCACFLayer> >& sublayers) - { - internalSetSublayers(sublayers); - checkLayerConsistency(); - } - - void insertSublayer(PassRefPtr<WKCACFLayer> layer, size_t index) { internalInsertSublayer(layer, index); } - - size_t sublayerCount() const { return internalSublayerCount(); } - - void removeFromSuperlayer(); - - WKCACFLayer* ancestorOrSelfWithSuperlayer(WKCACFLayer*) const; - - void setAnchorPoint(const CGPoint& p) { CACFLayerSetAnchorPoint(layer(), p); setNeedsCommit(); } - CGPoint anchorPoint() const { return CACFLayerGetAnchorPoint(layer()); } - - void setAnchorPointZ(CGFloat z) { CACFLayerSetAnchorPointZ(layer(), z); setNeedsCommit(); } - CGFloat anchorPointZ() const { return CACFLayerGetAnchorPointZ(layer()); } - - void setBackgroundColor(CGColorRef color) { CACFLayerSetBackgroundColor(layer(), color); setNeedsCommit(); } - CGColorRef backgroundColor() const { return CACFLayerGetBackgroundColor(layer()); } - - void setBorderColor(CGColorRef color) { CACFLayerSetBorderColor(layer(), color); setNeedsCommit(); } - CGColorRef borderColor() const { return CACFLayerGetBorderColor(layer()); } - - void setBorderWidth(CGFloat width) { CACFLayerSetBorderWidth(layer(), width); setNeedsCommit(); } - CGFloat borderWidth() const { return CACFLayerGetBorderWidth(layer()); } - - virtual void setBounds(const CGRect&); - CGRect bounds() const { return CACFLayerGetBounds(layer()); } - - void setContents(CFTypeRef contents) { CACFLayerSetContents(layer(), contents); setNeedsCommit(); } - CFTypeRef contents() const { return CACFLayerGetContents(layer()); } - - void setContentsRect(const CGRect& contentsRect) { CACFLayerSetContentsRect(layer(), contentsRect); setNeedsCommit(); } - CGRect contentsRect() const { return CACFLayerGetContentsRect(layer()); } - - void setContentsGravity(ContentsGravityType); - ContentsGravityType contentsGravity() const; - - void setDoubleSided(bool b) { CACFLayerSetDoubleSided(layer(), b); setNeedsCommit(); } - bool doubleSided() const { return CACFLayerIsDoubleSided(layer()); } - - void setEdgeAntialiasingMask(uint32_t mask) { CACFLayerSetEdgeAntialiasingMask(layer(), mask); setNeedsCommit(); } - uint32_t edgeAntialiasingMask() const { return CACFLayerGetEdgeAntialiasingMask(layer()); } - - virtual void setFrame(const CGRect&); - CGRect frame() const { return CACFLayerGetFrame(layer()); } - - void setHidden(bool hidden) { CACFLayerSetHidden(layer(), hidden); setNeedsCommit(); } - bool isHidden() const { return CACFLayerIsHidden(layer()); } - - void setMasksToBounds(bool b) { CACFLayerSetMasksToBounds(layer(), b); } - bool masksToBounds() const { return CACFLayerGetMasksToBounds(layer()); } - - void setMagnificationFilter(FilterType); - FilterType magnificationFilter() const; - - void setMinificationFilter(FilterType); - FilterType minificationFilter() const; - - void setMinificationFilterBias(float bias) { CACFLayerSetMinificationFilterBias(layer(), bias); } - float minificationFilterBias() const { return CACFLayerGetMinificationFilterBias(layer()); } - - void setName(const String& name) { CACFLayerSetName(layer(), RetainPtr<CFStringRef>(AdoptCF, name.createCFString()).get()); } - String name() const { return CACFLayerGetName(layer()); } - - void setNeedsDisplayOnBoundsChange(bool needsDisplay) { m_needsDisplayOnBoundsChange = needsDisplay; } - - void setOpacity(float opacity) { CACFLayerSetOpacity(layer(), opacity); setNeedsCommit(); } - float opacity() const { return CACFLayerGetOpacity(layer()); } - - void setOpaque(bool b) { CACFLayerSetOpaque(layer(), b); setNeedsCommit(); } - bool opaque() const { return CACFLayerIsOpaque(layer()); } - - void setPosition(const CGPoint& position) { CACFLayerSetPosition(layer(), position); setNeedsCommit(); } - CGPoint position() const { return CACFLayerGetPosition(layer()); } - - void setZPosition(CGFloat position) { CACFLayerSetZPosition(layer(), position); setNeedsCommit(); } - CGFloat zPosition() const { return CACFLayerGetZPosition(layer()); } - - void setSpeed(float speed) { CACFLayerSetSpeed(layer(), speed); } - CFTimeInterval speed() const { return CACFLayerGetSpeed(layer()); } - - void setTimeOffset(CFTimeInterval t) { CACFLayerSetTimeOffset(layer(), t); } - CFTimeInterval timeOffset() const { return CACFLayerGetTimeOffset(layer()); } - - WKCACFLayer* rootLayer() const; - - void setSublayerTransform(const CATransform3D& transform) { CACFLayerSetSublayerTransform(layer(), transform); setNeedsCommit(); } - CATransform3D sublayerTransform() const { return CACFLayerGetSublayerTransform(layer()); } - - WKCACFLayer* superlayer() const; - - void setTransform(const CATransform3D& transform) { CACFLayerSetTransform(layer(), transform); setNeedsCommit(); } - CATransform3D transform() const { return CACFLayerGetTransform(layer()); } - - void setGeometryFlipped(bool flipped) { CACFLayerSetGeometryFlipped(layer(), flipped); setNeedsCommit(); } - bool geometryFlipped() const { return CACFLayerIsGeometryFlipped(layer()); } - -#ifndef NDEBUG - // Print the tree from the root. Also does consistency checks - void printTree() const; -#endif - -protected: - WKCACFLayer(LayerType); - - void setNeedsCommit(); - - CACFLayerRef layer() const { return m_layer.get(); } - // This should only be called from removeFromSuperlayer. - void removeSublayer(const WKCACFLayer*); - - void checkLayerConsistency() - { -#ifndef NDEBUG - internalCheckLayerConsistency(); -#endif - } - - // Methods to be overridden for sublayer and rendering management - virtual WKCACFLayer* internalSublayerAtIndex(int) const; - - // Returns the index of the passed layer in this layer's sublayers list - // or -1 if not found - virtual int internalIndexOfSublayer(const WKCACFLayer*); - - virtual size_t internalSublayerCount() const; - virtual void internalInsertSublayer(PassRefPtr<WKCACFLayer>, size_t index); - virtual void internalRemoveAllSublayers(); - virtual void internalSetSublayers(const Vector<RefPtr<WKCACFLayer> >&); - - virtual void internalSetNeedsDisplay(const CGRect* dirtyRect); - -#ifndef NDEBUG - virtual void internalCheckLayerConsistency(); -#endif - -#ifndef NDEBUG - // Print this layer and its children to the console - void printLayer(int indent) const; -#endif - -private: - static void layoutSublayersProc(CACFLayerRef); - - RetainPtr<CACFLayerRef> m_layer; - WKCACFLayerLayoutClient* m_layoutClient; - bool m_needsDisplayOnBoundsChange; -}; - -} - -#endif // USE(ACCELERATED_COMPOSITING) - -#endif // WKCACFLayer_h diff --git a/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp b/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp index 4c5e61d..7c83f86 100644 --- a/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp +++ b/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.cpp @@ -187,7 +187,6 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client) , m_context(wkCACFContextCreate()) , m_hostWindow(0) , m_renderTimer(this, &WKCACFLayerRenderer::renderTimerFired) - , m_backingStoreDirty(false) , m_mustResetLostDeviceBeforeRendering(false) , m_syncLayerChanges(false) { @@ -224,32 +223,33 @@ WKCACFLayerRenderer::WKCACFLayerRenderer(WKCACFLayerRendererClient* client) WKCACFLayerRenderer::~WKCACFLayerRenderer() { - destroyRenderer(); + setHostWindow(0); + WKCACFContextFlusher::shared().removeContext(m_context); wkCACFContextDestroy(m_context); } -PlatformCALayer* WKCACFLayerRenderer::rootLayer() const +void WKCACFLayerRenderer::setHostWindow(HWND window) { - return m_rootLayer.get(); -} + if (window == m_hostWindow) + return; -void WKCACFLayerRenderer::addPendingAnimatedLayer(PassRefPtr<PlatformCALayer> layer) -{ - m_pendingAnimatedLayers.add(layer); + if (m_hostWindow) + destroyRenderer(); + + m_hostWindow = window; + + if (m_hostWindow) + createRenderer(); } -void WKCACFLayerRenderer::setRootContents(CGImageRef image) +PlatformCALayer* WKCACFLayerRenderer::rootLayer() const { - ASSERT(m_rootLayer); - m_rootLayer->setContents(image); - renderSoon(); + return m_rootLayer.get(); } -void WKCACFLayerRenderer::setRootContentsAndDisplay(CGImageRef image) +void WKCACFLayerRenderer::addPendingAnimatedLayer(PassRefPtr<PlatformCALayer> layer) { - ASSERT(m_rootLayer); - m_rootLayer->setContents(image); - paint(); + m_pendingAnimatedLayers.add(layer); } void WKCACFLayerRenderer::setRootChildLayer(PlatformCALayer* layer) @@ -266,16 +266,6 @@ void WKCACFLayerRenderer::layerTreeDidChange() renderSoon(); } -void WKCACFLayerRenderer::setNeedsDisplay(bool sync) -{ - if (!m_syncLayerChanges && sync) - m_syncLayerChanges = true; - - ASSERT(m_rootLayer); - m_rootLayer->setNeedsDisplay(0); - renderSoon(); -} - bool WKCACFLayerRenderer::createRenderer() { if (m_d3dDevice || !m_mightBeAbleToCreateDeviceLater) @@ -340,7 +330,7 @@ bool WKCACFLayerRenderer::createRenderer() initD3DGeometry(); - wkCACFContextInitializeD3DDevice(m_context, m_d3dDevice.get()); + wkCACFContextSetD3DDevice(m_context, m_d3dDevice.get()); if (IsWindow(m_hostWindow)) m_rootLayer->setBounds(bounds()); @@ -352,6 +342,7 @@ void WKCACFLayerRenderer::destroyRenderer() { wkCACFContextSetLayer(m_context, m_rootLayer->platformLayer()); + wkCACFContextSetD3DDevice(m_context, 0); m_d3dDevice = 0; if (s_d3d) s_d3d->Release(); @@ -422,15 +413,6 @@ void WKCACFLayerRenderer::paint() return; } - if (m_backingStoreDirty) { - // If the backing store is still dirty when we are about to draw the - // composited content, we need to force the window to paint into the - // backing store. The paint will only paint the dirty region that - // if being tracked in WebView. - UpdateWindow(m_hostWindow); - return; - } - Vector<CGRect> dirtyRects; getDirtyRects(m_hostWindow, dirtyRects); render(dirtyRects); @@ -545,6 +527,12 @@ void WKCACFLayerRenderer::renderSoon() m_renderTimer.startOneShot(0); } +void WKCACFLayerRenderer::syncCompositingStateSoon() +{ + m_syncLayerChanges = true; + renderSoon(); +} + CGRect WKCACFLayerRenderer::bounds() const { RECT clientRect; diff --git a/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.h b/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.h index aff1f83..02cdbdb 100644 --- a/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.h +++ b/Source/WebCore/platform/graphics/win/WKCACFLayerRenderer.h @@ -54,7 +54,6 @@ class WKCACFLayerRendererClient { public: virtual ~WKCACFLayerRendererClient() { } virtual bool shouldRender() const = 0; - virtual void animationsStarted(CFTimeInterval) { } virtual void syncCompositingState() { } }; @@ -70,17 +69,12 @@ public: static bool acceleratedCompositingAvailable(); - void setRootContents(CGImageRef); - void setRootContentsAndDisplay(CGImageRef); void setRootChildLayer(PlatformCALayer*); void layerTreeDidChange(); - void setNeedsDisplay(bool sync = false); - void setHostWindow(HWND window) { m_hostWindow = window; } - void setBackingStoreDirty(bool dirty) { m_backingStoreDirty = dirty; } - bool createRenderer(); - void destroyRenderer(); + void setHostWindow(HWND); + void paint(); void resize(); - void renderSoon(); + void syncCompositingStateSoon(); protected: PlatformCALayer* rootLayer() const; @@ -89,6 +83,9 @@ protected: private: WKCACFLayerRenderer(WKCACFLayerRendererClient*); + bool createRenderer(); + void destroyRenderer(); + void renderSoon(); void renderTimerFired(Timer<WKCACFLayerRenderer>*); CGRect bounds() const; @@ -102,7 +99,6 @@ private: bool resetDevice(ResetReason); void render(const Vector<CGRect>& dirtyRects = Vector<CGRect>()); - void paint(); WKCACFLayerRendererClient* m_client; bool m_mightBeAbleToCreateDeviceLater; @@ -112,7 +108,6 @@ private: WKCACFContext* m_context; HWND m_hostWindow; Timer<WKCACFLayerRenderer> m_renderTimer; - bool m_backingStoreDirty; bool m_mustResetLostDeviceBeforeRendering; bool m_syncLayerChanges; HashSet<RefPtr<PlatformCALayer> > m_pendingAnimatedLayers; |