michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_GFX_BASICCOMPOSITOR_H michael@0: #define MOZILLA_GFX_BASICCOMPOSITOR_H michael@0: michael@0: #include "mozilla/layers/Compositor.h" michael@0: #include "mozilla/layers/TextureHost.h" michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class gfxContext; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class BasicCompositingRenderTarget : public CompositingRenderTarget michael@0: { michael@0: public: michael@0: BasicCompositingRenderTarget(gfx::DrawTarget* aDrawTarget, const gfx::IntRect& aRect) michael@0: : CompositingRenderTarget(aRect.TopLeft()) michael@0: , mDrawTarget(aDrawTarget) michael@0: , mSize(aRect.Size()) michael@0: { } michael@0: michael@0: virtual gfx::IntSize GetSize() const MOZ_OVERRIDE { return mSize; } michael@0: michael@0: virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE michael@0: { michael@0: return mDrawTarget ? mDrawTarget->GetFormat() michael@0: : gfx::SurfaceFormat(gfx::SurfaceFormat::UNKNOWN); michael@0: } michael@0: michael@0: RefPtr mDrawTarget; michael@0: gfx::IntSize mSize; michael@0: }; michael@0: michael@0: class BasicCompositor : public Compositor michael@0: { michael@0: public: michael@0: BasicCompositor(nsIWidget *aWidget); michael@0: michael@0: virtual ~BasicCompositor(); michael@0: michael@0: michael@0: virtual bool Initialize() MOZ_OVERRIDE { return true; }; michael@0: michael@0: virtual void Destroy() MOZ_OVERRIDE; michael@0: michael@0: virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() MOZ_OVERRIDE michael@0: { michael@0: return TextureFactoryIdentifier(LayersBackend::LAYERS_BASIC, michael@0: XRE_GetProcessType(), michael@0: GetMaxTextureSize()); michael@0: } michael@0: michael@0: virtual TemporaryRef michael@0: CreateRenderTarget(const gfx::IntRect &aRect, SurfaceInitMode aInit) MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef michael@0: CreateRenderTargetFromSource(const gfx::IntRect &aRect, michael@0: const CompositingRenderTarget *aSource, michael@0: const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE; michael@0: michael@0: virtual TemporaryRef michael@0: CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; michael@0: michael@0: virtual bool SupportsEffect(EffectTypes aEffect) MOZ_OVERRIDE; michael@0: michael@0: virtual void SetRenderTarget(CompositingRenderTarget *aSource) MOZ_OVERRIDE michael@0: { michael@0: mRenderTarget = static_cast(aSource); michael@0: } michael@0: virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE michael@0: { michael@0: return mRenderTarget; michael@0: } michael@0: michael@0: virtual void DrawQuad(const gfx::Rect& aRect, michael@0: const gfx::Rect& aClipRect, michael@0: const EffectChain &aEffectChain, michael@0: gfx::Float aOpacity, michael@0: const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; michael@0: michael@0: virtual void BeginFrame(const nsIntRegion& aInvalidRegion, michael@0: const gfx::Rect *aClipRectIn, michael@0: const gfx::Matrix& aTransform, michael@0: const gfx::Rect& aRenderBounds, michael@0: gfx::Rect *aClipRectOut = nullptr, michael@0: gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; michael@0: virtual void EndFrame() MOZ_OVERRIDE; michael@0: virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE michael@0: { michael@0: NS_RUNTIMEABORT("We shouldn't ever hit this"); michael@0: } michael@0: virtual void AbortFrame() MOZ_OVERRIDE; michael@0: michael@0: virtual bool SupportsPartialTextureUpdate() { return true; } michael@0: virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE { return true; } michael@0: virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE { return INT32_MAX; } michael@0: virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE { } michael@0: virtual void SetTargetContext(gfx::DrawTarget* aTarget) MOZ_OVERRIDE michael@0: { michael@0: mCopyTarget = aTarget; michael@0: } michael@0: michael@0: virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE { michael@0: } michael@0: michael@0: virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) { } michael@0: michael@0: virtual void PrepareViewport(const gfx::IntSize& aSize, michael@0: const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE { } michael@0: michael@0: virtual const char* Name() const { return "Basic"; } michael@0: michael@0: virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { michael@0: return LayersBackend::LAYERS_BASIC; michael@0: } michael@0: michael@0: virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } michael@0: michael@0: gfx::DrawTarget *GetDrawTarget() { return mDrawTarget; } michael@0: michael@0: private: michael@0: michael@0: virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE { return mWidgetSize; } michael@0: michael@0: // Widget associated with this compositor michael@0: nsIWidget *mWidget; michael@0: gfx::IntSize mWidgetSize; michael@0: michael@0: // The final destination surface michael@0: RefPtr mDrawTarget; michael@0: // The current render target for drawing michael@0: RefPtr mRenderTarget; michael@0: // An optional destination target to copy the results michael@0: // to after drawing is completed. michael@0: RefPtr mCopyTarget; michael@0: michael@0: gfx::IntRect mInvalidRect; michael@0: nsIntRegion mInvalidRegion; michael@0: }; michael@0: michael@0: } // namespace layers michael@0: } // namespace mozilla michael@0: michael@0: #endif /* MOZILLA_GFX_BASICCOMPOSITOR_H */