|
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 "nsAutoPtr.h" |
|
13 |
|
14 class gfxContext; |
|
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 { } |
|
27 |
|
28 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } |
|
29 |
|
30 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE |
|
31 { |
|
32 return mDrawTarget ? mDrawTarget->GetFormat() |
|
33 : gfx::SurfaceFormat(gfx::SurfaceFormat::UNKNOWN); |
|
34 } |
|
35 |
|
36 RefPtr<gfx::DrawTarget> mDrawTarget; |
|
37 gfx::IntSize mSize; |
|
38 }; |
|
39 |
|
40 class BasicCompositor : public Compositor |
|
41 { |
|
42 public: |
|
43 BasicCompositor(nsIWidget *aWidget); |
|
44 |
|
45 virtual ~BasicCompositor(); |
|
46 |
|
47 |
|
48 virtual bool Initialize() MOZ_OVERRIDE { return true; }; |
|
49 |
|
50 virtual void Destroy() MOZ_OVERRIDE; |
|
51 |
|
52 virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE |
|
53 { |
|
54 return TextureFactoryIdentifier(LayersBackend::LAYERS_BASIC, |
|
55 XRE_GetProcessType(), |
|
56 GetMaxTextureSize()); |
|
57 } |
|
58 |
|
59 virtual TemporaryRef<CompositingRenderTarget> |
|
60 CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) MOZ_OVERRIDE; |
|
61 |
|
62 virtual TemporaryRef<CompositingRenderTarget> |
|
63 CreateRenderTargetFromSource(const gfx::IntRect &aRect, |
|
64 const CompositingRenderTarget *aSource, |
|
65 const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE; |
|
66 |
|
67 virtual TemporaryRef<DataTextureSource> |
|
68 CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; |
|
69 |
|
70 virtual bool SupportsEffect(EffectTypes aEffect) MOZ_OVERRIDE; |
|
71 |
|
72 virtual void SetRenderTarget(CompositingRenderTarget *aSource) MOZ_OVERRIDE |
|
73 { |
|
74 mRenderTarget = static_cast<BasicCompositingRenderTarget*>(aSource); |
|
75 } |
|
76 virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE |
|
77 { |
|
78 return mRenderTarget; |
|
79 } |
|
80 |
|
81 virtual void DrawQuad(const gfx::Rect& aRect, |
|
82 const gfx::Rect& aClipRect, |
|
83 const EffectChain &aEffectChain, |
|
84 gfx::Float aOpacity, |
|
85 const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; |
|
86 |
|
87 virtual void BeginFrame(const nsIntRegion& aInvalidRegion, |
|
88 const gfx::Rect *aClipRectIn, |
|
89 const gfx::Matrix& aTransform, |
|
90 const gfx::Rect& aRenderBounds, |
|
91 gfx::Rect *aClipRectOut = nullptr, |
|
92 gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; |
|
93 virtual void EndFrame() MOZ_OVERRIDE; |
|
94 virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE |
|
95 { |
|
96 NS_RUNTIMEABORT("We shouldn't ever hit this"); |
|
97 } |
|
98 virtual void AbortFrame() MOZ_OVERRIDE; |
|
99 |
|
100 virtual bool SupportsPartialTextureUpdate() { return true; } |
|
101 virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE { return true; } |
|
102 virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE { return INT32_MAX; } |
|
103 virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE { } |
|
104 virtual void SetTargetContext(gfx::DrawTarget* aTarget) MOZ_OVERRIDE |
|
105 { |
|
106 mCopyTarget = aTarget; |
|
107 } |
|
108 |
|
109 virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE { |
|
110 } |
|
111 |
|
112 virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) { } |
|
113 |
|
114 virtual void PrepareViewport(const gfx::IntSize& aSize, |
|
115 const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE { } |
|
116 |
|
117 virtual const char* Name() const { return "Basic"; } |
|
118 |
|
119 virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { |
|
120 return LayersBackend::LAYERS_BASIC; |
|
121 } |
|
122 |
|
123 virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } |
|
124 |
|
125 gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; } |
|
126 |
|
127 private: |
|
128 |
|
129 virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return mWidgetSize; } |
|
130 |
|
131 // Widget associated with this compositor |
|
132 nsIWidget *mWidget; |
|
133 gfx::IntSize mWidgetSize; |
|
134 |
|
135 // The final destination surface |
|
136 RefPtr<gfx::DrawTarget> mDrawTarget; |
|
137 // The current render target for drawing |
|
138 RefPtr<BasicCompositingRenderTarget> mRenderTarget; |
|
139 // An optional destination target to copy the results |
|
140 // to after drawing is completed. |
|
141 RefPtr<gfx::DrawTarget> mCopyTarget; |
|
142 |
|
143 gfx::IntRect mInvalidRect; |
|
144 nsIntRegion mInvalidRegion; |
|
145 }; |
|
146 |
|
147 } // namespace layers |
|
148 } // namespace mozilla |
|
149 |
|
150 #endif /* MOZILLA_GFX_BASICCOMPOSITOR_H */ |