Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
6 #ifndef MOZILLA_GFX_BASICCOMPOSITOR_H
7 #define MOZILLA_GFX_BASICCOMPOSITOR_H
9 #include "mozilla/layers/Compositor.h"
10 #include "mozilla/layers/TextureHost.h"
11 #include "mozilla/gfx/2D.h"
12 #include "nsAutoPtr.h"
14 class gfxContext;
16 namespace mozilla {
17 namespace layers {
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 { }
28 virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; }
30 virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE
31 {
32 return mDrawTarget ? mDrawTarget->GetFormat()
33 : gfx::SurfaceFormat(gfx::SurfaceFormat::UNKNOWN);
34 }
36 RefPtr<gfx::DrawTarget> mDrawTarget;
37 gfx::IntSize mSize;
38 };
40 class BasicCompositor : public Compositor
41 {
42 public:
43 BasicCompositor(nsIWidget *aWidget);
45 virtual ~BasicCompositor();
48 virtual bool Initialize() MOZ_OVERRIDE { return true; };
50 virtual void Destroy() MOZ_OVERRIDE;
52 virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE
53 {
54 return TextureFactoryIdentifier(LayersBackend::LAYERS_BASIC,
55 XRE_GetProcessType(),
56 GetMaxTextureSize());
57 }
59 virtual TemporaryRef<CompositingRenderTarget>
60 CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) MOZ_OVERRIDE;
62 virtual TemporaryRef<CompositingRenderTarget>
63 CreateRenderTargetFromSource(const gfx::IntRect &aRect,
64 const CompositingRenderTarget *aSource,
65 const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE;
67 virtual TemporaryRef<DataTextureSource>
68 CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE;
70 virtual bool SupportsEffect(EffectTypes aEffect) MOZ_OVERRIDE;
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 }
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;
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;
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 }
109 virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE {
110 }
112 virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) { }
114 virtual void PrepareViewport(const gfx::IntSize& aSize,
115 const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE { }
117 virtual const char* Name() const { return "Basic"; }
119 virtual LayersBackend GetBackendType() const MOZ_OVERRIDE {
120 return LayersBackend::LAYERS_BASIC;
121 }
123 virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; }
125 gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; }
127 private:
129 virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return mWidgetSize; }
131 // Widget associated with this compositor
132 nsIWidget *mWidget;
133 gfx::IntSize mWidgetSize;
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;
143 gfx::IntRect mInvalidRect;
144 nsIntRegion mInvalidRegion;
145 };
147 } // namespace layers
148 } // namespace mozilla
150 #endif /* MOZILLA_GFX_BASICCOMPOSITOR_H */