gfx/layers/basic/BasicThebesLayer.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:df8ec130c8b8
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef GFX_BASICTHEBESLAYER_H
7 #define GFX_BASICTHEBESLAYER_H
8
9 #include "Layers.h" // for ThebesLayer, LayerManager, etc
10 #include "RotatedBuffer.h" // for RotatedContentBuffer, etc
11 #include "BasicImplData.h" // for BasicImplData
12 #include "BasicLayers.h" // for BasicLayerManager
13 #include "gfxPoint.h" // for gfxPoint
14 #include "mozilla/RefPtr.h" // for RefPtr
15 #include "mozilla/gfx/BasePoint.h" // for BasePoint
16 #include "mozilla/layers/ContentClient.h" // for ContentClientBasic
17 #include "mozilla/mozalloc.h" // for operator delete
18 #include "nsDebug.h" // for NS_ASSERTION
19 #include "nsISupportsImpl.h" // for MOZ_COUNT_CTOR, etc
20 #include "nsRegion.h" // for nsIntRegion
21 class gfxContext;
22
23 namespace mozilla {
24 namespace layers {
25
26 class ReadbackProcessor;
27
28 class BasicThebesLayer : public ThebesLayer, public BasicImplData {
29 public:
30 typedef RotatedContentBuffer::PaintState PaintState;
31 typedef RotatedContentBuffer::ContentType ContentType;
32
33 BasicThebesLayer(BasicLayerManager* aLayerManager) :
34 ThebesLayer(aLayerManager,
35 static_cast<BasicImplData*>(MOZ_THIS_IN_INITIALIZER_LIST())),
36 mContentClient(nullptr)
37 {
38 MOZ_COUNT_CTOR(BasicThebesLayer);
39 }
40 virtual ~BasicThebesLayer()
41 {
42 MOZ_COUNT_DTOR(BasicThebesLayer);
43 }
44
45 virtual void SetVisibleRegion(const nsIntRegion& aRegion)
46 {
47 NS_ASSERTION(BasicManager()->InConstruction(),
48 "Can only set properties in construction phase");
49 ThebesLayer::SetVisibleRegion(aRegion);
50 }
51 virtual void InvalidateRegion(const nsIntRegion& aRegion)
52 {
53 NS_ASSERTION(BasicManager()->InConstruction(),
54 "Can only set properties in construction phase");
55 mInvalidRegion.Or(mInvalidRegion, aRegion);
56 mInvalidRegion.SimplifyOutward(20);
57 mValidRegion.Sub(mValidRegion, mInvalidRegion);
58 }
59
60 virtual void PaintThebes(gfxContext* aContext,
61 Layer* aMaskLayer,
62 LayerManager::DrawThebesLayerCallback aCallback,
63 void* aCallbackData,
64 ReadbackProcessor* aReadback);
65
66 virtual void Validate(LayerManager::DrawThebesLayerCallback aCallback,
67 void* aCallbackData) MOZ_OVERRIDE;
68
69 virtual void ClearCachedResources()
70 {
71 if (mContentClient) {
72 mContentClient->Clear();
73 }
74 mValidRegion.SetEmpty();
75 }
76
77 virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface)
78 {
79 if (!BasicManager()->IsRetained()) {
80 // Don't do any snapping of our transform, since we're just going to
81 // draw straight through without intermediate buffers.
82 mEffectiveTransform = GetLocalTransform() * aTransformToSurface;
83 if (gfxPoint(0,0) != mResidualTranslation) {
84 mResidualTranslation = gfxPoint(0,0);
85 mValidRegion.SetEmpty();
86 }
87 ComputeEffectiveTransformForMaskLayer(aTransformToSurface);
88 return;
89 }
90 ThebesLayer::ComputeEffectiveTransforms(aTransformToSurface);
91 }
92
93 BasicLayerManager* BasicManager()
94 {
95 return static_cast<BasicLayerManager*>(mManager);
96 }
97
98 protected:
99 virtual void
100 PaintBuffer(gfxContext* aContext,
101 const nsIntRegion& aRegionToDraw,
102 const nsIntRegion& aExtendedRegionToDraw,
103 const nsIntRegion& aRegionToInvalidate,
104 bool aDidSelfCopy,
105 DrawRegionClip aClip,
106 LayerManager::DrawThebesLayerCallback aCallback,
107 void* aCallbackData)
108 {
109 if (!aCallback) {
110 BasicManager()->SetTransactionIncomplete();
111 return;
112 }
113 aCallback(this, aContext, aExtendedRegionToDraw, aClip,
114 aRegionToInvalidate, aCallbackData);
115 // Everything that's visible has been validated. Do this instead of just
116 // OR-ing with aRegionToDraw, since that can lead to a very complex region
117 // here (OR doesn't automatically simplify to the simplest possible
118 // representation of a region.)
119 nsIntRegion tmp;
120 tmp.Or(mVisibleRegion, aExtendedRegionToDraw);
121 mValidRegion.Or(mValidRegion, tmp);
122 }
123
124 RefPtr<ContentClientBasic> mContentClient;
125 };
126
127 }
128 }
129
130 #endif

mercurial