Coverage Report

Created: 2018-09-25 14:53

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