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_MaskOperation_h
7 : #define mozilla_gfx_layers_mlgpu_MaskOperation_h
8 :
9 : #include "mozilla/RefPtr.h"
10 : #include "mozilla/gfx/Rect.h"
11 : #include "SharedBufferMLGPU.h"
12 : #include <vector>
13 :
14 : namespace mozilla {
15 : namespace layers {
16 :
17 : class FrameBuilder;
18 : class Layer;
19 : class MLGDevice;
20 : class MLGRenderTarget;
21 : class MLGTexture;
22 : class TextureSource;
23 :
24 : class MaskOperation
25 : {
26 0 : NS_INLINE_DECL_REFCOUNTING(MaskOperation)
27 :
28 : public:
29 : // For when the exact texture is known ahead of time.
30 : MaskOperation(FrameBuilder* aBuilder, MLGTexture* aSource);
31 :
32 : // Return the mask rectangle in screen coordinates. This function takes a
33 : // layer because a single-texture mask operation is not dependent on a
34 : // specific mask transform. (Multiple mask layer operations are, and they
35 : // ignore the layer parameter).
36 : virtual gfx::Rect ComputeMaskRect(Layer* aLayer) const;
37 :
38 0 : MLGTexture* GetTexture() const {
39 0 : return mTexture;
40 : }
41 :
42 : protected:
43 : explicit MaskOperation(FrameBuilder* aBuilder);
44 : virtual ~MaskOperation();
45 :
46 : protected:
47 : RefPtr<MLGTexture> mTexture;
48 : };
49 :
50 0 : struct MaskTexture
51 : {
52 : MaskTexture() : mSource(nullptr)
53 : {}
54 0 : MaskTexture(const gfx::Rect& aRect, TextureSource* aSource)
55 0 : : mRect(aRect), mSource(aSource)
56 0 : {}
57 :
58 : bool operator <(const MaskTexture& aOther) const;
59 :
60 : gfx::Rect mRect;
61 : RefPtr<TextureSource> mSource;
62 : };
63 :
64 : typedef std::vector<MaskTexture> MaskTextureList;
65 :
66 : class MaskCombineOperation final : public MaskOperation
67 : {
68 : public:
69 : explicit MaskCombineOperation(FrameBuilder* aBuilder);
70 : ~MaskCombineOperation() override;
71 :
72 : void Init(const MaskTextureList& aTextures);
73 :
74 : void PrepareForRendering();
75 : void Render();
76 :
77 0 : gfx::Rect ComputeMaskRect(Layer* aLayer) const override {
78 0 : return mArea;
79 : }
80 :
81 : private:
82 : FrameBuilder* mBuilder;
83 : gfx::Rect mArea;
84 : MaskTextureList mTextures;
85 : RefPtr<MLGRenderTarget> mTarget;
86 :
87 : std::vector<VertexBufferSection> mInputBuffers;
88 : };
89 :
90 : RefPtr<TextureSource> GetMaskLayerTexture(Layer* aLayer);
91 : void AppendToMaskTextureList(MaskTextureList& aList, Layer* aLayer);
92 :
93 : } // namespace layers
94 : } // namespace mozilla
95 :
96 : #endif // mozilla_gfx_layers_mlgpu_MaskOperation_h
|