/src/mozilla-central/gfx/layers/mlgpu/LayerMLGPU.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozilla_gfx_layers_mlgpu_LayerMLGPU_h |
8 | | #define mozilla_gfx_layers_mlgpu_LayerMLGPU_h |
9 | | |
10 | | #include "Layers.h" |
11 | | #include "mozilla/layers/LayerManagerComposite.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace layers { |
15 | | |
16 | | class CanvasLayerMLGPU; |
17 | | class ColorLayerMLGPU; |
18 | | class ContainerLayerMLGPU; |
19 | | class FrameBuilder; |
20 | | class ImageHost; |
21 | | class ImageLayerMLGPU; |
22 | | class LayerManagerMLGPU; |
23 | | class MaskOperation; |
24 | | class MLGRenderTarget; |
25 | | class PaintedLayerMLGPU; |
26 | | class RefLayerMLGPU; |
27 | | class RenderViewMLGPU; |
28 | | class TexturedLayerMLGPU; |
29 | | class TextureSource; |
30 | | |
31 | | class LayerMLGPU : public HostLayer |
32 | | { |
33 | | public: |
34 | 0 | LayerMLGPU* AsLayerMLGPU() override { return this; } |
35 | 0 | virtual PaintedLayerMLGPU* AsPaintedLayerMLGPU() { return nullptr; } |
36 | 0 | virtual ImageLayerMLGPU* AsImageLayerMLGPU() { return nullptr; } |
37 | 0 | virtual CanvasLayerMLGPU* AsCanvasLayerMLGPU() { return nullptr; } |
38 | 0 | virtual ContainerLayerMLGPU* AsContainerLayerMLGPU() { return nullptr; } |
39 | 0 | virtual RefLayerMLGPU* AsRefLayerMLGPU() { return nullptr; } |
40 | 0 | virtual ColorLayerMLGPU* AsColorLayerMLGPU() { return nullptr; } |
41 | 0 | virtual TexturedLayerMLGPU* AsTexturedLayerMLGPU() { return nullptr; } |
42 | | |
43 | | static void BeginFrame(); |
44 | | |
45 | | // Ask the layer to acquire any resources or per-frame information needed |
46 | | // to render. If this returns false, the layer will be skipped entirely. |
47 | | bool PrepareToRender(FrameBuilder* aBuilder, const RenderTargetIntRect& aClipRect); |
48 | | |
49 | 0 | Layer::LayerType GetType() { |
50 | 0 | return GetLayer()->GetType(); |
51 | 0 | } |
52 | 0 | const RenderTargetIntRect& GetComputedClipRect() const { |
53 | 0 | return mComputedClipRect; |
54 | 0 | } |
55 | 0 | MaskOperation* GetMask() const { |
56 | 0 | return mMask; |
57 | 0 | } |
58 | 0 | float GetComputedOpacity() const { |
59 | 0 | return mComputedOpacity; |
60 | 0 | } |
61 | | |
62 | | // Return the bounding box of this layer in render target space, clipped to |
63 | | // the computed clip rect, and rounded out to an integer rect. |
64 | | gfx::IntRect GetClippedBoundingBox(RenderViewMLGPU* aView, |
65 | | const Maybe<gfx::Polygon>& aGeometry); |
66 | | |
67 | | // If this layer has already been prepared for the current frame, return |
68 | | // true. This should only be used to guard against double-processing |
69 | | // container layers after 3d-sorting. |
70 | | bool IsPrepared() const { |
71 | | return mFrameKey == sFrameKey && mPrepared; |
72 | | } |
73 | | |
74 | | // Return true if the content in this layer is opaque (not factoring in |
75 | | // blend modes or opacity), false otherwise. |
76 | | virtual bool IsContentOpaque(); |
77 | | |
78 | | // Returns the region that this layer will draw pixels to. If the layer and |
79 | | // its content are opaque, this is the layer's opaque region. |
80 | 0 | const LayerIntRegion& GetRenderRegion() const { |
81 | 0 | return mRenderRegion; |
82 | 0 | } |
83 | | |
84 | | // Some layers have visible regions that extend beyond what is actually drawn. |
85 | | // When performing CPU-based occlusion culling we must clamp the visible region |
86 | | // to the actual area. Note that if a layer is opaque, it must not expand its |
87 | | // visible region such that it might include non-opaque pixels, as may be the |
88 | | // case for PaintedLayers with a restricted visible region. |
89 | | virtual void SetRenderRegion(LayerIntRegion&& aRegion); |
90 | | |
91 | | virtual void AssignToView(FrameBuilder* aBuilder, |
92 | | RenderViewMLGPU* aView, |
93 | | Maybe<gfx::Polygon>&& aGeometry); |
94 | | |
95 | | // Callback for when PrepareToRender has finished successfully. If this |
96 | | // returns false, PrepareToRender will return false. |
97 | | virtual bool OnPrepareToRender(FrameBuilder* aBuilder) { |
98 | | return true; |
99 | | } |
100 | | |
101 | 0 | virtual void ClearCachedResources() {} |
102 | | virtual CompositableHost* GetCompositableHost() override { |
103 | | return nullptr; |
104 | | } |
105 | | |
106 | | protected: |
107 | | LayerMLGPU(LayerManagerMLGPU* aManager); |
108 | | LayerManagerMLGPU* GetManager(); |
109 | | |
110 | | void AddBoundsToView(FrameBuilder* aBuilder, |
111 | | RenderViewMLGPU* aView, |
112 | | Maybe<gfx::Polygon>&& aGeometry); |
113 | | |
114 | | void MarkPrepared(); |
115 | | |
116 | | // We don't want derivative layers overriding this directly - we provide a |
117 | | // callback instead. |
118 | | void SetLayerManager(HostLayerManager* aManager) override; |
119 | 0 | virtual void OnLayerManagerChange(LayerManagerMLGPU* aManager) {} |
120 | | |
121 | | private: |
122 | | // This is a monotonic counter used to check whether a layer appears twice |
123 | | // when 3d sorting. |
124 | | static uint64_t sFrameKey; |
125 | | |
126 | | protected: |
127 | | // These are set during PrepareToRender. |
128 | | RenderTargetIntRect mComputedClipRect; |
129 | | RefPtr<MaskOperation> mMask; |
130 | | uint64_t mFrameKey; |
131 | | float mComputedOpacity; |
132 | | bool mPrepared; |
133 | | LayerIntRegion mRenderRegion; |
134 | | }; |
135 | | |
136 | | class RefLayerMLGPU final : public RefLayer |
137 | | , public LayerMLGPU |
138 | | { |
139 | | public: |
140 | | explicit RefLayerMLGPU(LayerManagerMLGPU* aManager); |
141 | | ~RefLayerMLGPU() override; |
142 | | |
143 | | // Layer |
144 | | HostLayer* AsHostLayer() override { return this; } |
145 | | RefLayerMLGPU* AsRefLayerMLGPU() override { return this; } |
146 | | Layer* GetLayer() override { return this; } |
147 | | |
148 | | // ContainerLayer |
149 | | void ComputeEffectiveTransforms(const gfx::Matrix4x4& aTransformToSurface) override |
150 | | { |
151 | | DefaultComputeEffectiveTransforms(aTransformToSurface); |
152 | | } |
153 | | |
154 | | const LayerIntRegion& GetShadowVisibleRegion() override; |
155 | | |
156 | | MOZ_LAYER_DECL_NAME("RefLayerMLGPU", TYPE_REF) |
157 | | }; |
158 | | |
159 | | class ColorLayerMLGPU final : public ColorLayer |
160 | | , public LayerMLGPU |
161 | | { |
162 | | public: |
163 | | explicit ColorLayerMLGPU(LayerManagerMLGPU* aManager); |
164 | | ~ColorLayerMLGPU() override; |
165 | | |
166 | | // LayerMLGPU |
167 | | bool IsContentOpaque() override { |
168 | | return mColor.a >= 1.0f; |
169 | | } |
170 | | |
171 | | // Layer |
172 | | HostLayer* AsHostLayer() override { return this; } |
173 | | ColorLayerMLGPU* AsColorLayerMLGPU() override { return this; } |
174 | | Layer* GetLayer() override { return this; } |
175 | | |
176 | | MOZ_LAYER_DECL_NAME("ColorLayerMLGPU", TYPE_COLOR) |
177 | | }; |
178 | | |
179 | | } // namespace layers |
180 | | } // namespace mozilla |
181 | | |
182 | | #endif // mozilla_gfx_layers_mlgpu_LayerMLGPU_h |