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_BASICCOMPOSITOR_H
7 : #define MOZILLA_GFX_BASICCOMPOSITOR_H
8 :
9 : #include "mozilla/layers/Compositor.h"
10 : #include "mozilla/layers/TextureHost.h"
11 : #include "mozilla/gfx/2D.h"
12 : #include "mozilla/gfx/Triangle.h"
13 : #include "mozilla/gfx/Polygon.h"
14 :
15 : namespace mozilla {
16 : namespace layers {
17 :
18 81 : class BasicCompositingRenderTarget : public CompositingRenderTarget
19 : {
20 : public:
21 27 : BasicCompositingRenderTarget(gfx::DrawTarget* aDrawTarget, const gfx::IntRect& aRect)
22 54 : : CompositingRenderTarget(aRect.TopLeft())
23 : , mDrawTarget(aDrawTarget)
24 54 : , mSize(aRect.Size())
25 27 : { }
26 :
27 0 : virtual const char* Name() const override { return "BasicCompositingRenderTarget"; }
28 :
29 0 : virtual gfx::IntSize GetSize() const override { return mSize; }
30 :
31 : void BindRenderTarget();
32 :
33 0 : virtual gfx::SurfaceFormat GetFormat() const override
34 : {
35 0 : return mDrawTarget ? mDrawTarget->GetFormat()
36 0 : : gfx::SurfaceFormat(gfx::SurfaceFormat::UNKNOWN);
37 : }
38 :
39 : RefPtr<gfx::DrawTarget> mDrawTarget;
40 : gfx::IntSize mSize;
41 : };
42 :
43 : class BasicCompositor : public Compositor
44 : {
45 : public:
46 : explicit BasicCompositor(CompositorBridgeParent* aParent, widget::CompositorWidget* aWidget);
47 :
48 : protected:
49 : virtual ~BasicCompositor();
50 :
51 : public:
52 :
53 0 : virtual BasicCompositor* AsBasicCompositor() override { return this; }
54 :
55 : virtual bool Initialize(nsCString* const out_failureReason) override;
56 :
57 : virtual void DetachWidget() override;
58 :
59 : virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override;
60 :
61 : virtual already_AddRefed<CompositingRenderTarget>
62 : CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) override;
63 :
64 : virtual already_AddRefed<CompositingRenderTarget>
65 : CreateRenderTargetFromSource(const gfx::IntRect &aRect,
66 : const CompositingRenderTarget *aSource,
67 : const gfx::IntPoint &aSourcePoint) override;
68 :
69 : virtual already_AddRefed<CompositingRenderTarget>
70 : CreateRenderTargetForWindow(const LayoutDeviceIntRect& aRect,
71 : const LayoutDeviceIntRect& aClearRect,
72 : BufferMode aBufferMode);
73 :
74 : virtual already_AddRefed<DataTextureSource>
75 : CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
76 :
77 : virtual already_AddRefed<DataTextureSource>
78 : CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) override;
79 :
80 : virtual already_AddRefed<DataTextureSource>
81 : CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) override;
82 :
83 : virtual bool SupportsEffect(EffectTypes aEffect) override;
84 :
85 : bool SupportsLayerGeometry() const override;
86 :
87 27 : virtual void SetRenderTarget(CompositingRenderTarget *aSource) override
88 : {
89 27 : mRenderTarget = static_cast<BasicCompositingRenderTarget*>(aSource);
90 27 : mRenderTarget->BindRenderTarget();
91 27 : }
92 0 : virtual CompositingRenderTarget* GetCurrentRenderTarget() const override
93 : {
94 0 : return mRenderTarget;
95 : }
96 :
97 : virtual void DrawQuad(const gfx::Rect& aRect,
98 : const gfx::IntRect& aClipRect,
99 : const EffectChain &aEffectChain,
100 : gfx::Float aOpacity,
101 : const gfx::Matrix4x4& aTransform,
102 : const gfx::Rect& aVisibleRect) override;
103 :
104 : virtual void ClearRect(const gfx::Rect& aRect) override;
105 :
106 : virtual void BeginFrame(const nsIntRegion& aInvalidRegion,
107 : const gfx::IntRect *aClipRectIn,
108 : const gfx::IntRect& aRenderBounds,
109 : const nsIntRegion& aOpaqueRegion,
110 : gfx::IntRect *aClipRectOut = nullptr,
111 : gfx::IntRect *aRenderBoundsOut = nullptr) override;
112 : virtual void EndFrame() override;
113 :
114 0 : virtual bool SupportsPartialTextureUpdate() override { return true; }
115 0 : virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) override { return true; }
116 : virtual int32_t GetMaxTextureSize() const override;
117 0 : virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) override { }
118 :
119 0 : virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) override {
120 0 : }
121 :
122 56 : virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) override { }
123 :
124 : #ifdef MOZ_DUMP_PAINTING
125 0 : virtual const char* Name() const override { return "Basic"; }
126 : #endif // MOZ_DUMP_PAINTING
127 :
128 0 : virtual LayersBackend GetBackendType() const override {
129 0 : return LayersBackend::LAYERS_BASIC;
130 : }
131 :
132 : gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; }
133 :
134 151 : virtual bool IsPendingComposite() override
135 : {
136 151 : return mIsPendingEndRemoteDrawing;
137 : }
138 :
139 : virtual void FinishPendingComposite() override;
140 :
141 : private:
142 :
143 : template<typename Geometry>
144 : void DrawGeometry(const Geometry& aGeometry,
145 : const gfx::Rect& aRect,
146 : const gfx::IntRect& aClipRect,
147 : const EffectChain& aEffectChain,
148 : gfx::Float aOpacity,
149 : const gfx::Matrix4x4& aTransform,
150 : const gfx::Rect& aVisibleRect,
151 : const bool aEnableAA);
152 :
153 : virtual void DrawPolygon(const gfx::Polygon& aPolygon,
154 : const gfx::Rect& aRect,
155 : const gfx::IntRect& aClipRect,
156 : const EffectChain& aEffectChain,
157 : gfx::Float aOpacity,
158 : const gfx::Matrix4x4& aTransform,
159 : const gfx::Rect& aVisibleRect) override;
160 :
161 : void TryToEndRemoteDrawing(bool aForceToEnd = false);
162 :
163 : bool NeedsToDeferEndRemoteDrawing();
164 :
165 : // The final destination surface
166 : RefPtr<gfx::DrawTarget> mDrawTarget;
167 : // The current render target for drawing
168 : RefPtr<BasicCompositingRenderTarget> mRenderTarget;
169 :
170 : LayoutDeviceIntRect mInvalidRect;
171 : LayoutDeviceIntRegion mInvalidRegion;
172 :
173 : uint32_t mMaxTextureSize;
174 : bool mIsPendingEndRemoteDrawing;
175 : };
176 :
177 : BasicCompositor* AssertBasicCompositor(Compositor* aCompositor);
178 :
179 : } // namespace layers
180 : } // namespace mozilla
181 :
182 : #endif /* MOZILLA_GFX_BASICCOMPOSITOR_H */
|