Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; 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_ContainerLayerComposite_H
7 : #define GFX_ContainerLayerComposite_H
8 :
9 : #include "Layers.h" // for Layer (ptr only), etc
10 : #include "mozilla/Attributes.h" // for override
11 : #include "mozilla/UniquePtr.h" // for UniquePtr
12 : #include "mozilla/layers/LayerManagerComposite.h"
13 : #include "mozilla/gfx/Rect.h"
14 :
15 : namespace mozilla {
16 : namespace layers {
17 :
18 : class CompositableHost;
19 : class CompositingRenderTarget;
20 : struct PreparedData;
21 :
22 : class ContainerLayerComposite : public ContainerLayer,
23 : public LayerComposite
24 : {
25 : template<class ContainerT>
26 : friend void ContainerPrepare(ContainerT* aContainer,
27 : LayerManagerComposite* aManager,
28 : const RenderTargetIntRect& aClipRect);
29 : template<class ContainerT>
30 : friend void ContainerRender(ContainerT* aContainer,
31 : LayerManagerComposite* aManager,
32 : const RenderTargetIntRect& aClipRect,
33 : const Maybe<gfx::Polygon>& aGeometry);
34 : template<class ContainerT>
35 : friend void RenderLayers(ContainerT* aContainer,
36 : LayerManagerComposite* aManager,
37 : const RenderTargetIntRect& aClipRect,
38 : const Maybe<gfx::Polygon>& aGeometry);
39 : template<class ContainerT>
40 : friend void RenderIntermediate(ContainerT* aContainer,
41 : LayerManagerComposite* aManager,
42 : const gfx::IntRect& aClipRect,
43 : RefPtr<CompositingRenderTarget> surface);
44 : template<class ContainerT>
45 : friend RefPtr<CompositingRenderTarget>
46 : CreateTemporaryTargetAndCopyFromBackground(ContainerT* aContainer,
47 : LayerManagerComposite* aManager,
48 : const RenderTargetIntRect& aClipRect);
49 : template<class ContainerT>
50 : friend RefPtr<CompositingRenderTarget>
51 : CreateOrRecycleTarget(ContainerT* aContainer,
52 : LayerManagerComposite* aManager,
53 : const RenderTargetIntRect& aClipRect);
54 :
55 : template<class ContainerT>
56 : void RenderMinimap(ContainerT* aContainer, LayerManagerComposite* aManager,
57 : const RenderTargetIntRect& aClipRect, Layer* aLayer);
58 : public:
59 : explicit ContainerLayerComposite(LayerManagerComposite *aManager);
60 :
61 : protected:
62 : ~ContainerLayerComposite();
63 :
64 : public:
65 : // LayerComposite Implementation
66 444 : virtual Layer* GetLayer() override { return this; }
67 :
68 0 : virtual void SetLayerManager(HostLayerManager* aManager) override
69 : {
70 0 : LayerComposite::SetLayerManager(aManager);
71 0 : mManager = aManager;
72 0 : mLastIntermediateSurface = nullptr;
73 0 : }
74 :
75 : virtual void Destroy() override;
76 :
77 : LayerComposite* GetFirstChildComposite() override;
78 :
79 : virtual void Cleanup() override;
80 :
81 : virtual void RenderLayer(const gfx::IntRect& aClipRect,
82 : const Maybe<gfx::Polygon>& aGeometry) override;
83 :
84 : virtual void Prepare(const RenderTargetIntRect& aClipRect) override;
85 :
86 65 : virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
87 : {
88 65 : DefaultComputeEffectiveTransforms(aTransformToSurface);
89 65 : }
90 :
91 : virtual void CleanupResources() override;
92 :
93 1820 : virtual HostLayer* AsHostLayer() override { return this; }
94 :
95 : // container layers don't use a compositable
96 0 : CompositableHost* GetCompositableHost() override { return nullptr; }
97 :
98 : // If the layer is marked as scale-to-resolution, add a post-scale
99 : // to the layer's transform equal to the pres shell resolution we're
100 : // scaling to. This cancels out the post scale of '1 / resolution'
101 : // added by Layout. TODO: It would be nice to get rid of both of these
102 : // post-scales.
103 685 : virtual float GetPostXScale() const override {
104 685 : if (mScaleToResolution) {
105 0 : return mSimpleAttrs.PostXScale() * mPresShellResolution;
106 : }
107 685 : return mSimpleAttrs.PostXScale();
108 : }
109 685 : virtual float GetPostYScale() const override {
110 685 : if (mScaleToResolution) {
111 0 : return mSimpleAttrs.PostYScale() * mPresShellResolution;
112 : }
113 685 : return mSimpleAttrs.PostYScale();
114 : }
115 :
116 64 : virtual const char* Name() const override { return "ContainerLayerComposite"; }
117 : UniquePtr<PreparedData> mPrepared;
118 :
119 : RefPtr<CompositingRenderTarget> mLastIntermediateSurface;
120 : };
121 :
122 : class RefLayerComposite : public RefLayer,
123 : public LayerComposite
124 : {
125 : template<class ContainerT>
126 : friend void ContainerPrepare(ContainerT* aContainer,
127 : LayerManagerComposite* aManager,
128 : const RenderTargetIntRect& aClipRect);
129 : template<class ContainerT>
130 : friend void ContainerRender(ContainerT* aContainer,
131 : LayerManagerComposite* aManager,
132 : const gfx::IntRect& aClipRect,
133 : const Maybe<gfx::Polygon>& aGeometry);
134 : template<class ContainerT>
135 : friend void RenderLayers(ContainerT* aContainer,
136 : LayerManagerComposite* aManager,
137 : const gfx::IntRect& aClipRect,
138 : const Maybe<gfx::Polygon>& aGeometry);
139 : template<class ContainerT>
140 : friend void RenderIntermediate(ContainerT* aContainer,
141 : LayerManagerComposite* aManager,
142 : const gfx::IntRect& aClipRect,
143 : RefPtr<CompositingRenderTarget> surface);
144 : template<class ContainerT>
145 : friend RefPtr<CompositingRenderTarget>
146 : CreateTemporaryTargetAndCopyFromBackground(ContainerT* aContainer,
147 : LayerManagerComposite* aManager,
148 : const gfx::IntRect& aClipRect);
149 : template<class ContainerT>
150 : friend RefPtr<CompositingRenderTarget>
151 : CreateTemporaryTarget(ContainerT* aContainer,
152 : LayerManagerComposite* aManager,
153 : const gfx::IntRect& aClipRect);
154 :
155 : public:
156 : explicit RefLayerComposite(LayerManagerComposite *aManager);
157 :
158 : protected:
159 : ~RefLayerComposite();
160 :
161 : public:
162 : /** LayerOGL implementation */
163 251 : Layer* GetLayer() override { return this; }
164 :
165 0 : virtual void SetLayerManager(HostLayerManager* aManager) override
166 : {
167 0 : LayerComposite::SetLayerManager(aManager);
168 0 : mManager = aManager;
169 0 : mLastIntermediateSurface = nullptr;
170 0 : }
171 :
172 : void Destroy() override;
173 :
174 : LayerComposite* GetFirstChildComposite() override;
175 :
176 : virtual void RenderLayer(const gfx::IntRect& aClipRect,
177 : const Maybe<gfx::Polygon>& aGeometry) override;
178 :
179 : virtual void Prepare(const RenderTargetIntRect& aClipRect) override;
180 :
181 29 : virtual void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override
182 : {
183 29 : DefaultComputeEffectiveTransforms(aTransformToSurface);
184 29 : }
185 :
186 : virtual void Cleanup() override;
187 :
188 : virtual void CleanupResources() override;
189 :
190 910 : virtual HostLayer* AsHostLayer() override { return this; }
191 :
192 : // ref layers don't use a compositable
193 0 : CompositableHost* GetCompositableHost() override { return nullptr; }
194 :
195 28 : virtual const char* Name() const override { return "RefLayerComposite"; }
196 : UniquePtr<PreparedData> mPrepared;
197 : RefPtr<CompositingRenderTarget> mLastIntermediateSurface;
198 : };
199 :
200 : } // namespace layers
201 : } // namespace mozilla
202 :
203 : #endif /* GFX_ContainerLayerComposite_H */
|