1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/basic/BasicCompositor.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,150 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 +* This Source Code Form is subject to the terms of the Mozilla Public 1.6 +* License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef MOZILLA_GFX_BASICCOMPOSITOR_H 1.10 +#define MOZILLA_GFX_BASICCOMPOSITOR_H 1.11 + 1.12 +#include "mozilla/layers/Compositor.h" 1.13 +#include "mozilla/layers/TextureHost.h" 1.14 +#include "mozilla/gfx/2D.h" 1.15 +#include "nsAutoPtr.h" 1.16 + 1.17 +class gfxContext; 1.18 + 1.19 +namespace mozilla { 1.20 +namespace layers { 1.21 + 1.22 +class BasicCompositingRenderTarget : public CompositingRenderTarget 1.23 +{ 1.24 +public: 1.25 + BasicCompositingRenderTarget(gfx::DrawTarget* aDrawTarget, const gfx::IntRect& aRect) 1.26 + : CompositingRenderTarget(aRect.TopLeft()) 1.27 + , mDrawTarget(aDrawTarget) 1.28 + , mSize(aRect.Size()) 1.29 + { } 1.30 + 1.31 + virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } 1.32 + 1.33 + virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE 1.34 + { 1.35 + return mDrawTarget ? mDrawTarget->GetFormat() 1.36 + : gfx::SurfaceFormat(gfx::SurfaceFormat::UNKNOWN); 1.37 + } 1.38 + 1.39 + RefPtr<gfx::DrawTarget> mDrawTarget; 1.40 + gfx::IntSize mSize; 1.41 +}; 1.42 + 1.43 +class BasicCompositor : public Compositor 1.44 +{ 1.45 +public: 1.46 + BasicCompositor(nsIWidget *aWidget); 1.47 + 1.48 + virtual ~BasicCompositor(); 1.49 + 1.50 + 1.51 + virtual bool Initialize() MOZ_OVERRIDE { return true; }; 1.52 + 1.53 + virtual void Destroy() MOZ_OVERRIDE; 1.54 + 1.55 + virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE 1.56 + { 1.57 + return TextureFactoryIdentifier(LayersBackend::LAYERS_BASIC, 1.58 + XRE_GetProcessType(), 1.59 + GetMaxTextureSize()); 1.60 + } 1.61 + 1.62 + virtual TemporaryRef<CompositingRenderTarget> 1.63 + CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) MOZ_OVERRIDE; 1.64 + 1.65 + virtual TemporaryRef<CompositingRenderTarget> 1.66 + CreateRenderTargetFromSource(const gfx::IntRect &aRect, 1.67 + const CompositingRenderTarget *aSource, 1.68 + const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE; 1.69 + 1.70 + virtual TemporaryRef<DataTextureSource> 1.71 + CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; 1.72 + 1.73 + virtual bool SupportsEffect(EffectTypes aEffect) MOZ_OVERRIDE; 1.74 + 1.75 + virtual void SetRenderTarget(CompositingRenderTarget *aSource) MOZ_OVERRIDE 1.76 + { 1.77 + mRenderTarget = static_cast<BasicCompositingRenderTarget*>(aSource); 1.78 + } 1.79 + virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE 1.80 + { 1.81 + return mRenderTarget; 1.82 + } 1.83 + 1.84 + virtual void DrawQuad(const gfx::Rect& aRect, 1.85 + const gfx::Rect& aClipRect, 1.86 + const EffectChain &aEffectChain, 1.87 + gfx::Float aOpacity, 1.88 + const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; 1.89 + 1.90 + virtual void BeginFrame(const nsIntRegion& aInvalidRegion, 1.91 + const gfx::Rect *aClipRectIn, 1.92 + const gfx::Matrix& aTransform, 1.93 + const gfx::Rect& aRenderBounds, 1.94 + gfx::Rect *aClipRectOut = nullptr, 1.95 + gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; 1.96 + virtual void EndFrame() MOZ_OVERRIDE; 1.97 + virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE 1.98 + { 1.99 + NS_RUNTIMEABORT("We shouldn't ever hit this"); 1.100 + } 1.101 + virtual void AbortFrame() MOZ_OVERRIDE; 1.102 + 1.103 + virtual bool SupportsPartialTextureUpdate() { return true; } 1.104 + virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE { return true; } 1.105 + virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE { return INT32_MAX; } 1.106 + virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE { } 1.107 + virtual void SetTargetContext(gfx::DrawTarget* aTarget) MOZ_OVERRIDE 1.108 + { 1.109 + mCopyTarget = aTarget; 1.110 + } 1.111 + 1.112 + virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE { 1.113 + } 1.114 + 1.115 + virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) { } 1.116 + 1.117 + virtual void PrepareViewport(const gfx::IntSize& aSize, 1.118 + const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE { } 1.119 + 1.120 + virtual const char* Name() const { return "Basic"; } 1.121 + 1.122 + virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { 1.123 + return LayersBackend::LAYERS_BASIC; 1.124 + } 1.125 + 1.126 + virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } 1.127 + 1.128 + gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; } 1.129 + 1.130 +private: 1.131 + 1.132 + virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return mWidgetSize; } 1.133 + 1.134 + // Widget associated with this compositor 1.135 + nsIWidget *mWidget; 1.136 + gfx::IntSize mWidgetSize; 1.137 + 1.138 + // The final destination surface 1.139 + RefPtr<gfx::DrawTarget> mDrawTarget; 1.140 + // The current render target for drawing 1.141 + RefPtr<BasicCompositingRenderTarget> mRenderTarget; 1.142 + // An optional destination target to copy the results 1.143 + // to after drawing is completed. 1.144 + RefPtr<gfx::DrawTarget> mCopyTarget; 1.145 + 1.146 + gfx::IntRect mInvalidRect; 1.147 + nsIntRegion mInvalidRegion; 1.148 +}; 1.149 + 1.150 +} // namespace layers 1.151 +} // namespace mozilla 1.152 + 1.153 +#endif /* MOZILLA_GFX_BASICCOMPOSITOR_H */