WebCore/ChangeLog

 12011-01-06 Chris Marrin <cmarrin@apple.com>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Share code between Mac (CA) and Windows (CACF) GraphicsLayer implementations
 6 https://bugs.webkit.org/show_bug.cgi?id=49388
 7
 8 Changed PlatformCALayer API. Added PlatformCALayerClient abstract class which is
 9 used to communicate from PlatformCALayer to the owner. This replaces passing
 10 GraphicsLayerCA pointer when creating PlatformCALayer. It also includes the
 11 API that used to be in PlatformCALayerLayout. GraphicsLayerCA now implements
 12 the PlatformCALayerClient API.
 13
 14 This change has little impact on the Mac side but makes the Windows
 15 interface simpler, especially when handling video layers on Windows.
 16
 17 * WebCore.xcodeproj/project.pbxproj:
 18 * config.h:
 19 * platform/graphics/GraphicsLayer.h:
 20 (WebCore::GraphicsLayer::layerDidDisplay):
 21 (WebCore::GraphicsLayer::showDebugBorders):
 22 (WebCore::GraphicsLayer::showRepaintCounter):
 23 * platform/graphics/ca/GraphicsLayerCA.cpp:
 24 (WebCore::GraphicsLayerCA::platformCALayerAnimationStarted):
 25 (WebCore::GraphicsLayerCA::setContentsToImage):
 26 (WebCore::GraphicsLayerCA::setContentsToMedia):
 27 (WebCore::GraphicsLayerCA::layerDidDisplay):
 28 (WebCore::GraphicsLayerCA::updateSublayerList):
 29 * platform/graphics/ca/GraphicsLayerCA.h:
 30 (WebCore::GraphicsLayerCA::platformCALayerLayoutSublayersOfLayer):
 31 (WebCore::GraphicsLayerCA::platformCALayerRespondsToLayoutChanges):
 32 (WebCore::GraphicsLayerCA::platformCALayerContentsOrientation):
 33 (WebCore::GraphicsLayerCA::platformCALayerPaintContents):
 34 (WebCore::GraphicsLayerCA::platformCALayerShowDebugBorders):
 35 (WebCore::GraphicsLayerCA::platformCALayerShowRepaintCounter):
 36 (WebCore::GraphicsLayerCA::platformCALayerIncrementRepaintCount):
 37 (WebCore::GraphicsLayerCA::platformCALayerContentsOpaque):
 38 (WebCore::GraphicsLayerCA::platformCALayerDrawsContent):
 39 (WebCore::GraphicsLayerCA::platformCALayerLayerDidDisplay):
 40 (WebCore::GraphicsLayerCA::platformCALayer):
 41 * platform/graphics/ca/PlatformCALayer.h:
 42 (WebCore::PlatformCALayer::owner):
 43 (WebCore::PlatformCALayer::animationStarted):
 44 * platform/graphics/ca/PlatformCALayerClient.h: Added.
 45 (WebCore::PlatformCALayerClient::~PlatformCALayerClient):
 46 * platform/graphics/ca/mac/PlatformCALayerMac.mm:
 47 (PlatformCALayer::setOwner):
 48 (PlatformCALayer::create):
 49 (PlatformCALayer::PlatformCALayer):
 50 (PlatformCALayer::contents):
 51 (PlatformCALayer::setContents):
 52 * platform/graphics/mac/WebGLLayer.mm:
 53 (-[WebGLLayer display]):
 54 * platform/graphics/mac/WebLayer.h:
 55 * platform/graphics/mac/WebLayer.mm:
 56 (drawLayerContents):
 57 (setLayerNeedsDisplayInRect):
 58 (-[WebLayer setNeedsDisplay]):
 59 (-[WebLayer display]):
 60 * platform/graphics/mac/WebTiledLayer.mm:
 61 (-[WebTiledLayer setNeedsDisplay]):
 62 (-[WebTiledLayer display]):
 63 * rendering/RenderLayerBacking.cpp:
 64 (WebCore::RenderLayerBacking::showDebugBorders):
 65 (WebCore::RenderLayerBacking::showRepaintCounter):
 66 * rendering/RenderLayerCompositor.cpp:
 67 (WebCore::RenderLayerCompositor::ensureRootPlatformLayer):
 68 * rendering/RenderLayerCompositor.h:
 69 (WebCore::RenderLayerCompositor::compositorShowDebugBorders):
 70 (WebCore::RenderLayerCompositor::compositorShowRepaintCounter):
 71 (WebCore::RenderLayerCompositor::notifyAnimationStarted):
 72 (WebCore::RenderLayerCompositor::notifySyncRequired):
 73 (WebCore::RenderLayerCompositor::paintContents):
 74 (WebCore::RenderLayerCompositor::showDebugBorders):
 75 (WebCore::RenderLayerCompositor::showRepaintCounter):
 76
1772011-01-06 Patrick Gansterer <paroga@webkit.org>
278
379 Reviewed by Eric Seidel.
75190

WebCore/config.h

@@typedef float CGFloat;
220220#define WTF_USE_SAFARI_THEME 1
221221#endif
222222
 223// CoreAnimation is available to IOS, Mac and Windows if using CG
 224#if PLATFORM(MAC) || PLATFORM(IOS) || (PLATFORM(WIN) && PLATFORM(CG))
 225#define WTF_PLATFORM_CA 1
 226#endif
 227
223228#if PLATFORM(QT) && USE(V8) && defined(Q_WS_X11)
224229/* protect ourselves from evil X11 defines */
225230#include <bridge/npruntime_internal.h>
75123

WebCore/WebCore.xcodeproj/project.pbxproj

10051005 490707E61219C04300D90E51 /* ANGLEWebKitBridge.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */; };
10061006 490707E71219C04300D90E51 /* ANGLEWebKitBridge.h in Headers */ = {isa = PBXBuildFile; fileRef = 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */; };
10071007 492863991253B8FC00F792D6 /* ResourceLoadInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 492863981253B8FC00F792D6 /* ResourceLoadInfo.h */; settings = {ATTRIBUTES = (Private, ); }; };
 1008 493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 493E5E0812D6420500020081 /* PlatformCALayerClient.h */; };
10081009 49484FC1102CF23C00187DD3 /* CanvasGradient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */; };
10091010 49484FC2102CF23C00187DD3 /* CanvasGradient.h in Headers */ = {isa = PBXBuildFile; fileRef = 49484FB4102CF23C00187DD3 /* CanvasGradient.h */; };
10101011 49484FC4102CF23C00187DD3 /* CanvasPattern.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49484FB6102CF23C00187DD3 /* CanvasPattern.cpp */; };

73297330 490707E41219C04300D90E51 /* ANGLEWebKitBridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEWebKitBridge.cpp; sourceTree = "<group>"; };
73307331 490707E51219C04300D90E51 /* ANGLEWebKitBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANGLEWebKitBridge.h; sourceTree = "<group>"; };
73317332 492863981253B8FC00F792D6 /* ResourceLoadInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ResourceLoadInfo.h; sourceTree = "<group>"; };
 7333 493E5E0812D6420500020081 /* PlatformCALayerClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformCALayerClient.h; path = ca/PlatformCALayerClient.h; sourceTree = "<group>"; };
73327334 49484FB3102CF23C00187DD3 /* CanvasGradient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CanvasGradient.cpp; path = canvas/CanvasGradient.cpp; sourceTree = "<group>"; };
73337335 49484FB4102CF23C00187DD3 /* CanvasGradient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CanvasGradient.h; path = canvas/CanvasGradient.h; sourceTree = "<group>"; };
73347336 49484FB5102CF23C00187DD3 /* CanvasGradient.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = CanvasGradient.idl; path = canvas/CanvasGradient.idl; sourceTree = "<group>"; };

1323513237 499B3ED5128CD31400E726C2 /* GraphicsLayerCA.h */,
1323613238 499B3EDC128DB50100E726C2 /* PlatformCAAnimation.h */,
1323713239 499B3EC3128CCC4700E726C2 /* PlatformCALayer.h */,
 13240 493E5E0812D6420500020081 /* PlatformCALayerClient.h */,
1323813241 494BC40C12AEDD9E00743BD2 /* TransformationMatrixCA.cpp */,
1323913242 );
1324013243 name = ca;

2226522268 7EE6846D12D26E3800E79415 /* ResourceRequest.h in Headers */,
2226622269 7EE6846F12D26E3800E79415 /* ResourceRequestCFNet.h in Headers */,
2226722270 7EE6847012D26E3800E79415 /* ResourceResponse.h in Headers */,
 22271 493E5E0912D6420500020081 /* PlatformCALayerClient.h in Headers */,
2226822272 );
2226922273 runOnlyForDeploymentPostprocessing = 0;
2227022274 };
75123

WebCore/platform/graphics/GraphicsLayer.h

@@typedef CALayer PlatformLayer;
5353typedef void* PlatformLayer;
5454#endif
5555#elif PLATFORM(WIN)
56 namespace WebCore {
57 class WKCACFLayer;
58 typedef WKCACFLayer PlatformLayer;
59 }
 56typedef struct _CACFLayer PlatformLayer;
6057#elif PLATFORM(QT)
6158#if USE(TEXTURE_MAPPER)
6259namespace WebCore {

@@public:
314311 // Callback from the underlying graphics system to draw layer contents.
315312 void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip);
316313 // Callback from the underlying graphics system when the layer has been displayed
317  virtual void didDisplay(PlatformLayer*) { }
 314 virtual void layerDidDisplay(PlatformLayer*) { }
318315
319316 // For hosting this GraphicsLayer in a native layer hierarchy.
320317 virtual PlatformLayer* platformLayer() const { return 0; }

@@public:
330327 virtual void setContentsOrientation(CompositingCoordinatesOrientation orientation) { m_contentsOrientation = orientation; }
331328 CompositingCoordinatesOrientation contentsOrientation() const { return m_contentsOrientation; }
332329
333  bool showDebugBorders() { return m_client ? m_client->showDebugBorders() : false; }
334  bool showRepaintCounter() { return m_client ? m_client->showRepaintCounter() : false; }
 330 bool showDebugBorders() const { return m_client ? m_client->showDebugBorders() : false; }
 331 bool showRepaintCounter() const { return m_client ? m_client->showRepaintCounter() : false; }
335332
336333 void updateDebugIndicators();
337334
75123

WebCore/platform/graphics/ca/GraphicsLayerCA.cpp

@@void GraphicsLayerCA::removeAnimation(co
640640 noteLayerPropertyChanged(AnimationChanged);
641641}
642642
643 void GraphicsLayerCA::animationStarted(CFTimeInterval startTime)
 643void GraphicsLayerCA::platformCALayerAnimationStarted(CFTimeInterval startTime)
644644{
645645 if (m_client)
646646 m_client->notifyAnimationStarted(this, startTime);

@@void GraphicsLayerCA::setContentsToImage
660660
661661 m_uncorrectedContentsImage = newImage;
662662 m_pendingContentsImage = newImage;
 663
 664#if !PLATFORM(WIN)
663665 CGColorSpaceRef colorSpace = CGImageGetColorSpace(m_pendingContentsImage.get());
664666
665667 static CGColorSpaceRef deviceRGB = CGColorSpaceCreateDeviceRGB();

@@void GraphicsLayerCA::setContentsToImage
669671 static CGColorSpaceRef genericRGB = CGDisplayCopyColorSpace(kCGDirectMainDisplay);
670672 m_pendingContentsImage.adoptCF(CGImageCreateCopyWithColorSpace(m_pendingContentsImage.get(), genericRGB));
671673 }
 674#endif
672675 m_contentsLayerPurpose = ContentsLayerForImage;
673676 if (!m_contentsLayer)
674677 noteSublayersChanged();

@@void GraphicsLayerCA::setContentsToMedia
688691 if (m_contentsLayer && mediaLayer == m_contentsLayer->platformLayer())
689692 return;
690693
691  // Create the PlatformCALayer to wrap the incoming layer
692  m_contentsLayer = mediaLayer ? PlatformCALayer::create(mediaLayer, this) : 0;
693 
 694 // FIXME: The passed in layer might be a raw layer or an externally created
 695 // PlatformCALayer. To determine this we attempt to get the
 696 // PlatformCALayer pointer. If this returns a null pointer we assume it's
 697 // raw. This test might be invalid if the raw layer is, for instance, the
 698 // PlatformCALayer is using a user data pointer in the raw layer, and
 699 // the creator of the raw layer is using it for some other purpose.
 700 // For now we don't support such a case.
 701 PlatformCALayer* platformCALayer = PlatformCALayer::platformCALayer(mediaLayer);
 702 m_contentsLayer = mediaLayer ? (platformCALayer ? platformCALayer : PlatformCALayer::create(mediaLayer, this)) : 0;
694703 m_contentsLayerPurpose = mediaLayer ? ContentsLayerForMedia : NoContentsLayer;
695704
696705 noteSublayersChanged();

@@void GraphicsLayerCA::setContentsToCanva
711720 noteLayerPropertyChanged(ContentsCanvasLayerChanged);
712721}
713722
714 void GraphicsLayerCA::didDisplay(PlatformLayer* layer)
 723void GraphicsLayerCA::layerDidDisplay(PlatformLayer* layer)
715724{
716725 PlatformCALayer* currentLayer = PlatformCALayer::platformCALayer(layer);
717726 PlatformCALayer* sourceLayer;

@@void GraphicsLayerCA::updateSublayerList
903912 newSublayers.append(childLayer);
904913 }
905914
906  for (size_t i = 0; i < newSublayers.size(); ++i)
 915 for (int i = newSublayers.size() - 1; i >= 0; --i)
907916 newSublayers[i]->removeFromSuperlayer();
908917 }
909918
75123

WebCore/platform/graphics/ca/GraphicsLayerCA.h

3131#include "GraphicsLayer.h"
3232#include "Image.h"
3333#include "PlatformCAAnimation.h"
 34#include "PlatformCALayerClient.h"
3435#include <wtf/HashMap.h>
3536#include <wtf/HashSet.h>
3637#include <wtf/RetainPtr.h>

@@namespace WebCore {
4041
4142class PlatformCALayer;
4243
43 class GraphicsLayerCA : public GraphicsLayer {
 44class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
4445public:
4546 // The width and height of a single tile in a tiled layer. Should be large enough to
4647 // avoid lots of small tiles (and therefore lots of drawing callbacks), but small enough

@@public:
4950
5051 GraphicsLayerCA(GraphicsLayerClient*);
5152 virtual ~GraphicsLayerCA();
52 
53  virtual void animationStarted(CFTimeInterval beginTime);
 53
 54 // PlatformCALayerClient overrides
 55 virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) { }
 56 virtual bool platformCALayerRespondsToLayoutChanges() const { return false; }
 57
 58 virtual void platformCALayerAnimationStarted(CFTimeInterval beginTime);
 59 virtual CompositingCoordinatesOrientation platformCALayerContentsOrientation() const { return contentsOrientation(); }
 60 virtual void platformCALayerPaintContents(GraphicsContext& context, const IntRect& clip) { paintGraphicsLayerContents(context, clip); }
 61 virtual bool platformCALayerShowDebugBorders() const { return showDebugBorders(); }
 62 virtual bool platformCALayerShowRepaintCounter() const { return showRepaintCounter(); }
 63 virtual int platformCALayerIncrementRepaintCount() { return incrementRepaintCount(); }
 64
 65 virtual bool platformCALayerContentsOpaque() const { return contentsOpaque(); }
 66 virtual bool platformCALayerDrawsContent() const { return drawsContent(); }
 67 virtual void platformCALayerLayerDidDisplay(PlatformLayer* layer) { return layerDidDisplay(layer); }
5468
5569 virtual void setName(const String&);
5670
5771 virtual PlatformLayer* platformLayer() const;
 72 virtual PlatformCALayer* platformCALayer() const { return primaryLayer(); }
5873
5974 virtual bool setChildren(const Vector<GraphicsLayer*>&);
6075 virtual void addChild(GraphicsLayer*);

@@public:
112127 virtual void setDebugBackgroundColor(const Color&);
113128 virtual void setDebugBorder(const Color&, float borderWidth);
114129
115  virtual void didDisplay(PlatformLayer*);
 130 virtual void layerDidDisplay(PlatformLayer*);
116131
117132 void recursiveCommitChanges();
118133
75123

WebCore/platform/graphics/ca/PlatformCALayer.h

2929#if USE(ACCELERATED_COMPOSITING)
3030
3131#include "GraphicsContext.h"
32 #include "GraphicsLayerCA.h"
3332#include "PlatformCAAnimation.h"
 33#include "PlatformCALayerClient.h"
3434#include "PlatformString.h"
3535#include <wtf/HashMap.h>
3636#include <wtf/PassRefPtr.h>

@@typedef Vector<RefPtr<PlatformCALayer> >
4747
4848class PlatformCALayer : public RefCounted<PlatformCALayer> {
4949public:
50  // TiledLayer used in GraphicsLayer has constant settings:
51  // cTiledLayerTileSize = 512
52  // setTileSize:(cTiledLayerTileSize, cTiledLayerTileSize)
53  // setLevelsOfDetail:1
54  // setLevelsOfDetailBias:0
55  // setContentsGravity:@"bottomLeft"
56  //
57  // TiledLayer also has drawing functions like WebLayer
58  //
59  // WebLayer is a CALayer with drawing functions specific to WebKit
60  //
61  // Layer and TransformLayer are used as is
62 
63  enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeTransformLayer, LayerTypeWebTiledLayer, LayerTypeCustom };
 50 // LayerTypeRootLayer is used on some platforms. It has no backing store, so setNeedsDisplay
 51 // should not call CACFLayerSetNeedsDisplay, but rather just notify the renderer that it
 52 // has changed and should be re-rendered.
 53 enum LayerType { LayerTypeLayer, LayerTypeWebLayer, LayerTypeTransformLayer, LayerTypeWebTiledLayer, LayerTypeRootLayer, LayerTypeCustom };
6454 enum FilterType { Linear, Nearest, Trilinear };
6555
66  static PassRefPtr<PlatformCALayer> create(LayerType, GraphicsLayerCA*);
 56 static PassRefPtr<PlatformCALayer> create(LayerType, PlatformCALayerClient*);
6757
6858 // This function passes the layer as a void* rather than a PlatformLayer because PlatformLayer
6959 // is defined differently for Obj C and C++. This allows callers from both languages.
70  static PassRefPtr<PlatformCALayer> create(void* platformLayer, GraphicsLayerCA*);
 60 static PassRefPtr<PlatformCALayer> create(void* platformLayer, PlatformCALayerClient*);
7161
7262 ~PlatformCALayer();
7363

@@public:
7666 static PlatformCALayer* platformCALayer(void* platformLayer);
7767
7868 PlatformLayer* platformLayer() const;
 69
 70 PlatformCALayer* rootLayer() const;
7971
8072 static bool isValueFunctionSupported();
8173
82  GraphicsLayerCA* owner() const { return m_owner; }
83  void setOwner(GraphicsLayerCA* owner);
 74 PlatformCALayerClient* owner() const { return m_owner; }
 75 void setOwner(PlatformCALayerClient*);
8476
8577 void animationStarted(CFTimeInterval beginTime)
8678 {
8779 if (m_owner)
88  m_owner->animationStarted(beginTime);
 80 m_owner->platformCALayerAnimationStarted(beginTime);
8981 }
9082
 83 // Layout support
 84 void setNeedsLayout();
 85
 86
9187 void setNeedsDisplay(const FloatRect* dirtyRect = 0);
9288
 89 // This tells the layer tree to commit changes and perform a render, without do a setNeedsDisplay on any layer.
 90 void setNeedsCommit();
 91
9392 void setContentsChanged();
9493
9594 LayerType layerType() const { return m_layerType; }

@@public:
104103 size_t sublayerCount() const;
105104
106105 // This method removes the sublayers from the source and reparents them to the current layer.
 106 // Any sublayers previously in the current layer are removed.
107107 void adoptSublayers(PlatformCALayer* source);
108108
109109 void addAnimationForKey(const String& key, PlatformCAAnimation* animation);

@@public:
150150 bool acceleratesDrawing() const;
151151 void setAcceleratesDrawing(bool);
152152
153  void* contents() const;
154  void setContents(void*);
 153 CFTypeRef contents() const;
 154 void setContents(CFTypeRef);
155155
156156 FloatRect contentsRect() const;
157157 void setContentsRect(const FloatRect&);

@@public:
183183 CFTimeInterval timeOffset() const;
184184 void setTimeOffset(CFTimeInterval);
185185
 186#if PLATFORM(WIN) && !defined(NDEBUG)
 187 void printTree() const;
 188#endif
 189
186190protected:
187  PlatformCALayer(LayerType, PlatformLayer*, GraphicsLayerCA*);
 191 PlatformCALayer(LayerType, PlatformLayer*, PlatformCALayerClient*);
188192
189193private:
190 
191  GraphicsLayerCA* m_owner;
 194 PlatformCALayerClient* m_owner;
192195 LayerType m_layerType;
193196
194197#if PLATFORM(MAC) || PLATFORM(WIN)
195198 RetainPtr<PlatformLayer> m_layer;
196199#endif
197200
 201#if PLATFORM(WIN)
 202 HashMap<String, RefPtr<PlatformCAAnimation> > m_animations;
 203#endif
 204
198205#if PLATFORM(MAC)
199206#ifdef __OBJC__
200207 RetainPtr<NSObject> m_delegate;
75123

WebCore/platform/graphics/ca/PlatformCALayerClient.h

 1/*
 2 * Copyright (C) 2010 Apple Inc. All rights reserved.
 3 *
 4 * Redistribution and use in source and binary forms, with or without
 5 * modification, are permitted provided that the following conditions
 6 * are met:
 7 * 1. Redistributions of source code must retain the above copyright
 8 * notice, this list of conditions and the following disclaimer.
 9 * 2. Redistributions in binary form must reproduce the above copyright
 10 * notice, this list of conditions and the following disclaimer in the
 11 * documentation and/or other materials provided with the distribution.
 12 *
 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 24 */
 25
 26#ifndef PlatformCALayerClient_h
 27#define PlatformCALayerClient_h
 28
 29#if USE(ACCELERATED_COMPOSITING)
 30
 31#include "GraphicsContext.h"
 32#include "GraphicsLayer.h"
 33#include "PlatformCAAnimation.h"
 34#include "PlatformString.h"
 35#include <wtf/HashMap.h>
 36#include <wtf/PassRefPtr.h>
 37#include <wtf/RefCounted.h>
 38#include <wtf/RetainPtr.h>
 39#include <wtf/Vector.h>
 40#include <wtf/text/StringHash.h>
 41
 42namespace WebCore {
 43
 44class PlatformCALayer;
 45
 46class PlatformCALayerClient {
 47public:
 48 virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) = 0;
 49 virtual bool platformCALayerRespondsToLayoutChanges() const = 0;
 50
 51 virtual void platformCALayerAnimationStarted(CFTimeInterval beginTime) = 0;
 52 virtual GraphicsLayer::CompositingCoordinatesOrientation platformCALayerContentsOrientation() const = 0;
 53 virtual void platformCALayerPaintContents(GraphicsContext&, const IntRect& inClip) = 0;
 54 virtual bool platformCALayerShowDebugBorders() const = 0;
 55 virtual bool platformCALayerShowRepaintCounter() const = 0;
 56 virtual int platformCALayerIncrementRepaintCount() = 0;
 57
 58 virtual bool platformCALayerContentsOpaque() const = 0;
 59 virtual bool platformCALayerDrawsContent() const = 0;
 60 virtual void platformCALayerLayerDidDisplay(PlatformLayer*) = 0;
 61
 62protected:
 63 virtual ~PlatformCALayerClient() {}
 64};
 65
 66}
 67
 68#endif // USE(ACCELERATED_COMPOSITING)
 69
 70#endif // PlatformCALayerClient_h
0

WebCore/platform/graphics/ca/mac/PlatformCALayerMac.mm

@@bool PlatformCALayer::isValueFunctionSup
105105 return sHaveValueFunction;
106106}
107107
108 void PlatformCALayer::setOwner(GraphicsLayerCA* owner)
 108void PlatformCALayer::setOwner(PlatformCALayerClient* owner)
109109{
110110 m_owner = owner;
111111

@@static NSString* toCAFilterType(Platform
145145}
146146#endif
147147
148 PassRefPtr<PlatformCALayer> PlatformCALayer::create(LayerType layerType, GraphicsLayerCA* owner)
 148PassRefPtr<PlatformCALayer> PlatformCALayer::create(LayerType layerType, PlatformCALayerClient* owner)
149149{
150150 return adoptRef(new PlatformCALayer(layerType, 0, owner));
151151}
152152
153 PassRefPtr<PlatformCALayer> PlatformCALayer::create(void* platformLayer, GraphicsLayerCA* owner)
 153PassRefPtr<PlatformCALayer> PlatformCALayer::create(void* platformLayer, PlatformCALayerClient* owner)
154154{
155155 return adoptRef(new PlatformCALayer(LayerTypeCustom, static_cast<PlatformLayer*>(platformLayer), owner));
156156}
157157
158 PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, GraphicsLayerCA* owner)
 158PlatformCALayer::PlatformCALayer(LayerType layerType, PlatformLayer* layer, PlatformCALayerClient* owner)
159159 : m_owner(owner)
160160{
161161 BEGIN_BLOCK_OBJC_EXCEPTIONS

@@PlatformCALayer::PlatformCALayer(LayerTy
168168 Class layerClass = Nil;
169169 switch(layerType) {
170170 case LayerTypeLayer:
 171 case LayerTypeRootLayer:
171172 layerClass = [CALayer class];
172173 break;
173174 case LayerTypeWebLayer:

@@void PlatformCALayer::setAcceleratesDraw
568569#endif
569570}
570571
571 void* PlatformCALayer::contents() const
 572CFTypeRef PlatformCALayer::contents() const
572573{
573574 return [m_layer.get() contents];
574575}
575576
576 void PlatformCALayer::setContents(void* value)
 577void PlatformCALayer::setContents(CFTypeRef value)
577578{
578579 BEGIN_BLOCK_OBJC_EXCEPTIONS
579  [m_layer.get() setContents:static_cast<id>(value)];
 580 [m_layer.get() setContents:static_cast<id>(const_cast<void*>(value))];
580581 END_BLOCK_OBJC_EXCEPTIONS
581582}
582583
75123

WebCore/platform/graphics/mac/WebGLLayer.mm

@@- (void)display
144144{
145145 [super display];
146146 if (m_layerOwner)
147  m_layerOwner->didDisplay(self);
 147 m_layerOwner->layerDidDisplay(self);
148148}
149149
150150@end
75123

WebCore/platform/graphics/mac/WebLayer.h

3232
3333namespace WebCore {
3434 class GraphicsLayer;
 35 class PlatformCALayerClient;
3536}
3637
3738#if defined(BUILDING_ON_LEOPARD)

@@@interface WebLayer : CALayer
4748@end
4849
4950// Functions allows us to share implementation across WebTiledLayer and WebLayer
50 void drawLayerContents(CGContextRef, CALayer *, WebCore::GraphicsLayer*);
51 void setLayerNeedsDisplayInRect(CALayer *, WebCore::GraphicsLayer*, CGRect);
 51void drawLayerContents(CGContextRef, CALayer *, WebCore::PlatformCALayerClient*);
 52void setLayerNeedsDisplayInRect(CALayer *, WebCore::PlatformCALayerClient*, CGRect);
5253
5354#endif // USE(ACCELERATED_COMPOSITING)
5455
75123

WebCore/platform/graphics/mac/WebLayer.mm

@@using namespace WebCore;
4040
4141@implementation WebLayer
4242
43 void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::GraphicsLayer* layerContents)
 43void drawLayerContents(CGContextRef context, CALayer *layer, WebCore::PlatformCALayerClient* layerContents)
4444{
4545 if (!layerContents)
4646 return;

@@void drawLayerContents(CGContextRef cont
4848 CGContextSaveGState(context);
4949
5050 CGRect layerBounds = [layer bounds];
51  if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) {
 51 if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp) {
5252 CGContextScaleCTM(context, 1, -1);
5353 CGContextTranslateCTM(context, 0, -layerBounds.size.height);
5454 }
5555
56  if (layerContents->client()) {
57  [NSGraphicsContext saveGraphicsState];
 56 [NSGraphicsContext saveGraphicsState];
5857
59  // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
60  // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
61  NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
62  [NSGraphicsContext setCurrentContext:layerContext];
63 
64  GraphicsContext graphicsContext(context);
65 
66  if (!layerContents->contentsOpaque()) {
67  // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
68  graphicsContext.setShouldSmoothFonts(false);
69  }
70 
71  // It's important to get the clip from the context, because it may be significantly
72  // smaller than the layer bounds (e.g. tiled layers)
73  CGRect clipBounds = CGContextGetClipBoundingBox(context);
74  IntRect clip(enclosingIntRect(clipBounds));
75  layerContents->paintGraphicsLayerContents(graphicsContext, clip);
76 
77  [NSGraphicsContext restoreGraphicsState];
 58 // Set up an NSGraphicsContext for the context, so that parts of AppKit that rely on
 59 // the current NSGraphicsContext (e.g. NSCell drawing) get the right one.
 60 NSGraphicsContext* layerContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES];
 61 [NSGraphicsContext setCurrentContext:layerContext];
 62
 63 GraphicsContext graphicsContext(context);
 64
 65 if (!layerContents->platformCALayerContentsOpaque()) {
 66 // Turn off font smoothing to improve the appearance of text rendered onto a transparent background.
 67 graphicsContext.setShouldSmoothFonts(false);
7868 }
79 #ifndef NDEBUG
80  else {
81  ASSERT_NOT_REACHED();
 69
 70 // It's important to get the clip from the context, because it may be significantly
 71 // smaller than the layer bounds (e.g. tiled layers)
 72 CGRect clipBounds = CGContextGetClipBoundingBox(context);
 73 IntRect clip(enclosingIntRect(clipBounds));
 74 layerContents->platformCALayerPaintContents(graphicsContext, clip);
8275
83  // FIXME: ideally we'd avoid calling -setNeedsDisplay on a layer that is a plain color,
84  // so CA never makes backing store for it (which is what -setNeedsDisplay will do above).
85  CGContextSetRGBFillColor(context, 0.0f, 1.0f, 0.0f, 1.0f);
86  CGContextFillRect(context, layerBounds);
87  }
88 #endif
 76 [NSGraphicsContext restoreGraphicsState];
8977
90  if (layerContents->showRepaintCounter()) {
 78 if (layerContents->platformCALayerShowRepaintCounter()) {
9179 bool isTiledLayer = [layer isKindOfClass:[CATiledLayer class]];
9280
9381 char text[16]; // that's a lot of repaints
94  snprintf(text, sizeof(text), "%d", layerContents->incrementRepaintCount());
 82 snprintf(text, sizeof(text), "%d", layerContents->platformCALayerIncrementRepaintCount());
9583
9684 CGContextSaveGState(context);
9785 if (isTiledLayer)

@@void drawLayerContents(CGContextRef cont
117105 CGContextRestoreGState(context);
118106}
119107
120 void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::GraphicsLayer* layerContents, CGRect rect)
 108void setLayerNeedsDisplayInRect(CALayer *layer, WebCore::PlatformCALayerClient* layerContents, CGRect rect)
121109{
122  if (layerContents && layerContents->client() && layerContents->drawsContent()) {
 110 if (layerContents && layerContents->platformCALayerDrawsContent()) {
123111 struct objc_super layerSuper = { layer, class_getSuperclass(object_getClass(layer)) };
124112#if defined(BUILDING_ON_LEOPARD)
125113 rect = CGRectApplyAffineTransform(rect, [layer contentsTransform]);
126114#else
127  if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
 115 if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
128116 rect.origin.y = [layer bounds].size.height - rect.origin.y - rect.size.height;
129117#endif
130118 objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), rect);
131119
132120#ifndef NDEBUG
133  if (layerContents->showRepaintCounter()) {
 121 if (layerContents->platformCALayerShowRepaintCounter()) {
134122 CGRect bounds = [layer bounds];
135123 CGRect indicatorRect = CGRectMake(bounds.origin.x, bounds.origin.y, 46, 25);
136124#if defined(BUILDING_ON_LEOPARD)
137125 indicatorRect = CGRectApplyAffineTransform(indicatorRect, [layer contentsTransform]);
138126#else
139  if (layerContents->contentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
 127 if (layerContents->platformCALayerContentsOrientation() == WebCore::GraphicsLayer::CompositingCoordinatesBottomUp)
140128 indicatorRect.origin.y = [layer bounds].size.height - indicatorRect.origin.y - indicatorRect.size.height;
141129#endif
142130 objc_msgSendSuper(&layerSuper, @selector(setNeedsDisplayInRect:), indicatorRect);

@@- (id<CAAction>)actionForKey:(NSString *
155143- (void)setNeedsDisplay
156144{
157145 PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
158  if (layer && layer->owner() && layer->owner()->client() && layer->owner()->drawsContent())
 146 if (layer && layer->owner() && layer->owner()->platformCALayerDrawsContent())
159147 [super setNeedsDisplay];
160148}
161149

@@- (void)display
171159 [super display];
172160 PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
173161 if (layer && layer->owner())
174  layer->owner()->didDisplay(self);
 162 layer->owner()->platformCALayerLayerDidDisplay(self);
175163}
176164
177165- (void)drawInContext:(CGContextRef)context
75123

WebCore/platform/graphics/mac/WebTiledLayer.mm

@@- (id<CAAction>)actionForKey:(NSString *
6060- (void)setNeedsDisplay
6161{
6262 PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
63  if (layer && layer->owner() && layer->owner()->client() && layer->owner()->drawsContent())
 63 if (layer && layer->owner() && layer->owner()->platformCALayerDrawsContent())
6464 [super setNeedsDisplay];
6565}
6666

@@- (void)display
7676 [super display];
7777 PlatformCALayer* layer = PlatformCALayer::platformCALayer(self);
7878 if (layer && layer->owner())
79  layer->owner()->didDisplay(self);
 79 layer->owner()->platformCALayerLayerDidDisplay(self);
8080}
8181
8282- (void)drawInContext:(CGContextRef)context
75123

WebCore/rendering/RenderLayerBacking.cpp

@@void RenderLayerBacking::paintContents(c
11011101
11021102bool RenderLayerBacking::showDebugBorders() const
11031103{
1104  return compositor() ? compositor()->showDebugBorders() : false;
 1104 return compositor() ? compositor()->compositorShowDebugBorders() : false;
11051105}
11061106
11071107bool RenderLayerBacking::showRepaintCounter() const
11081108{
1109  return compositor() ? compositor()->showRepaintCounter() : false;
 1109 return compositor() ? compositor()->compositorShowRepaintCounter() : false;
11101110}
11111111
11121112bool RenderLayerBacking::startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes)
75123

WebCore/rendering/RenderLayerCompositor.cpp

@@void RenderLayerCompositor::ensureRootPl
13511351 if (!m_clipLayer) {
13521352 ASSERT(!m_scrollLayer);
13531353 // Create a clipping layer if this is an iframe
1354  m_clipLayer = GraphicsLayer::create(0);
 1354 m_clipLayer = GraphicsLayer::create(this);
13551355#ifndef NDEBUG
13561356 m_clipLayer->setName("iframe Clipping");
13571357#endif
13581358 m_clipLayer->setMasksToBounds(true);
13591359
1360  m_scrollLayer = GraphicsLayer::create(0);
 1360 m_scrollLayer = GraphicsLayer::create(this);
13611361#ifndef NDEBUG
13621362 m_scrollLayer->setName("iframe scrolling");
13631363#endif
75123

WebCore/rendering/RenderLayerCompositor.h

@@enum CompositingUpdateType {
5454//
5555// There is one RenderLayerCompositor per RenderView.
5656
57 class RenderLayerCompositor {
 57class RenderLayerCompositor : public GraphicsLayerClient {
5858public:
5959 RenderLayerCompositor(RenderView*);
6060 ~RenderLayerCompositor();
61 
 61
6262 // Return true if this RenderView is in "compositing mode" (i.e. has one or more
6363 // composited RenderLayers)
6464 bool inCompositingMode() const { return m_compositing; }

@@public:
7171
7272 bool canRender3DTransforms() const;
7373
74  bool showDebugBorders() const { return m_showDebugBorders; }
75  bool showRepaintCounter() const { return m_showRepaintCounter; }
76 
7774 // Copy the accelerated compositing related flags from Settings
7875 void cacheAcceleratedCompositingFlags();
7976

@@public:
172169
173170 String layerTreeAsText();
174171
 172 // These are named to avoid conflicts with the functions in GraphicsLayerClient
 173 // These return the actual internal variables.
 174 bool compositorShowDebugBorders() const { return m_showDebugBorders; }
 175 bool compositorShowRepaintCounter() const { return m_showRepaintCounter; }
 176
175177private:
 178 // GraphicsLayerClient Implementation
 179 virtual void notifyAnimationStarted(const GraphicsLayer*, double) { }
 180 virtual void notifySyncRequired(const GraphicsLayer*) { scheduleSync(); }
 181 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect&) { }
 182
 183 // These calls return false always. They are saying that the layers associated with this client
 184 // (the clipLayer and scrollLayer) should never show debugging info.
 185 virtual bool showDebugBorders() const { return false; }
 186 virtual bool showRepaintCounter() const { return false; }
 187
176188 // Whether the given RL needs a compositing layer.
177189 bool needsToBeComposited(const RenderLayer*) const;
178190 // Whether the layer has an intrinsic need for compositing layer.
75123