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 mozilla_gfx_layers_mlgpu_RenderViewMLGPU_h
7 : #define mozilla_gfx_layers_mlgpu_RenderViewMLGPU_h
8 :
9 : #include "LayerManagerMLGPU.h"
10 : #include "ClearRegionHelper.h"
11 : #include "RenderPassMLGPU.h"
12 : #include "Units.h"
13 : #include <deque>
14 :
15 : namespace mozilla {
16 : namespace layers {
17 :
18 : class FrameBuilder;
19 : class ContainerLayerMLGPU;
20 : class MLGRenderTarget;
21 :
22 : class RenderViewMLGPU
23 : {
24 : public:
25 0 : NS_INLINE_DECL_REFCOUNTING(RenderViewMLGPU)
26 :
27 : // Constructor for the widget render target.
28 : RenderViewMLGPU(FrameBuilder* aBuilder,
29 : MLGRenderTarget* aTarget,
30 : const nsIntRegion& aInvalidRegion);
31 :
32 : // Constructor for intermediate surfaces.
33 : RenderViewMLGPU(FrameBuilder* aBuilder,
34 : ContainerLayerMLGPU* aContainer,
35 : RenderViewMLGPU* aParent);
36 :
37 : void Prepare();
38 : void Render();
39 : void AddChild(RenderViewMLGPU* aParent);
40 : void AddItem(LayerMLGPU* aItem,
41 : const gfx::IntRect& aBounds,
42 : Maybe<gfx::Polygon>&& aGeometry);
43 : void FinishBuilding();
44 :
45 0 : const gfx::IntPoint& GetTargetOffset() const {
46 0 : return mTargetOffset;
47 : }
48 : RenderViewMLGPU* GetParent() const {
49 : return mParent;
50 : }
51 0 : bool HasDepthBuffer() const {
52 0 : return mUseDepthBuffer;
53 : }
54 :
55 : // The size and render target cannot be read until the view has finished
56 : // building, since we try to right-size the render target to the visible
57 : // region.
58 : MLGRenderTarget* GetRenderTarget() const;
59 : gfx::IntSize GetSize() const;
60 :
61 0 : gfx::IntRect GetInvalidRect() const {
62 0 : return mInvalidBounds;
63 : }
64 :
65 : private:
66 : RenderViewMLGPU(FrameBuilder* aBuilder, RenderViewMLGPU* aParent);
67 : ~RenderViewMLGPU();
68 :
69 : void ExecuteRendering();
70 : bool UpdateVisibleRegion(ItemInfo& aItem);
71 : void AddItemFrontToBack(LayerMLGPU* aLayer, ItemInfo& aItem);
72 : void AddItemBackToFront(LayerMLGPU* aLayer, ItemInfo& aItem);
73 :
74 : void PrepareClears();
75 :
76 : void ExecutePass(RenderPassMLGPU* aPass);
77 :
78 : // Return the sorting index offset to use.
79 : int32_t PrepareDepthBuffer();
80 :
81 : private:
82 : std::deque<RefPtr<RenderPassMLGPU>> mFrontToBack;
83 : std::deque<RefPtr<RenderPassMLGPU>> mBackToFront;
84 :
85 : FrameBuilder* mBuilder;
86 : RefPtr<MLGDevice> mDevice;
87 : RenderViewMLGPU* mParent;
88 : std::vector<RefPtr<RenderViewMLGPU>> mChildren;
89 :
90 : // Shader data.
91 : ConstantBufferSection mWorldConstants;
92 :
93 : // Information for the initial target surface clear. This covers the area that
94 : // won't be occluded by opaque content.
95 : ClearRegionHelper mPreClear;
96 :
97 : // The post-clear region, that must be cleared after all drawing is done.
98 : nsIntRegion mPostClearRegion;
99 : ClearRegionHelper mPostClear;
100 :
101 : // Either an MLGSwapChain-derived render target, or an intermediate surface.
102 : RefPtr<MLGRenderTarget> mTarget;
103 :
104 : // For intermediate render targets only, this is the layer owning the render target.
105 : ContainerLayerMLGPU* mContainer;
106 :
107 : // The offset adjustment from container layer space to render target space.
108 : // This is 0,0 for the root view.
109 : gfx::IntPoint mTargetOffset;
110 :
111 : // The invalid bounds as computed by LayerTreeInvalidation. This is the initial
112 : // render bounds size, if invalidation is disabled.
113 : gfx::IntRect mInvalidBounds;
114 :
115 : // The occluded region, which is updated every time we process an opaque,
116 : // rectangular item. This is not actually in LayerPixels, we do this to
117 : // avoid FromUnknownRegion which has array copies.
118 : LayerIntRegion mOccludedRegion;
119 :
120 : // True if we've finished adding layers to the view.
121 : bool mFinishedBuilding;
122 :
123 : // This state is used to avoid changing buffers while we execute batches.
124 : size_t mCurrentLayerBufferIndex;
125 : size_t mCurrentMaskRectBufferIndex;
126 :
127 : // Depth-buffer tracking.
128 : int32_t mNextSortIndex;
129 : bool mUseDepthBuffer;
130 : bool mDepthBufferNeedsClear;
131 : };
132 :
133 : } // namespace layers
134 : } // namespace mozilla
135 :
136 : #endif // mozilla_gfx_layers_mlgpu_RenderViewMLGPU_h
|