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_COMPOSITORD3D9_H michael@0: #define MOZILLA_GFX_COMPOSITORD3D9_H michael@0: michael@0: #include "mozilla/gfx/2D.h" michael@0: #include "gfx2DGlue.h" michael@0: #include "mozilla/layers/Compositor.h" michael@0: #include "mozilla/layers/TextureD3D9.h" michael@0: #include "DeviceManagerD3D9.h" michael@0: michael@0: class nsWidget; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class CompositorD3D9 : public Compositor michael@0: { michael@0: public: michael@0: CompositorD3D9(PCompositorParent* aParent, nsIWidget *aWidget); michael@0: ~CompositorD3D9(); michael@0: michael@0: virtual bool Initialize() MOZ_OVERRIDE; michael@0: virtual void Destroy() MOZ_OVERRIDE {} michael@0: michael@0: virtual TextureFactoryIdentifier michael@0: GetTextureFactoryIdentifier() MOZ_OVERRIDE; michael@0: michael@0: virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE; michael@0: virtual int32_t GetMaxTextureSize() const MOZ_FINAL; michael@0: michael@0: virtual void SetTargetContext(gfx::DrawTarget *aTarget) MOZ_OVERRIDE michael@0: { michael@0: mTarget = aTarget; michael@0: } michael@0: michael@0: virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {} michael@0: michael@0: virtual TemporaryRef michael@0: CreateRenderTarget(const gfx::IntRect &aRect, michael@0: 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 void SetRenderTarget(CompositingRenderTarget *aSurface); michael@0: virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE michael@0: { michael@0: return mCurrentRT; michael@0: } michael@0: michael@0: virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {} michael@0: michael@0: virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE; 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: michael@0: virtual void EndFrame() MOZ_OVERRIDE; michael@0: michael@0: virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {} michael@0: michael@0: virtual void AbortFrame() MOZ_OVERRIDE {} michael@0: michael@0: virtual void PrepareViewport(const gfx::IntSize& aSize, michael@0: const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE; michael@0: michael@0: virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE{ return true; } michael@0: michael@0: #ifdef MOZ_DUMP_PAINTING michael@0: virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D9"; } michael@0: #endif michael@0: michael@0: virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { michael@0: return LayersBackend::LAYERS_D3D9; michael@0: } michael@0: michael@0: virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } michael@0: michael@0: IDirect3DDevice9* device() const michael@0: { michael@0: return mDeviceManager michael@0: ? mDeviceManager->device() michael@0: : nullptr; michael@0: } michael@0: michael@0: /** michael@0: * Returns true if the Compositor is ready to go. michael@0: * D3D9 devices can be awkward and there is a bunch of logic around michael@0: * resetting/recreating devices and swap chains. That is handled by this method. michael@0: * If we don't have a device and swap chain ready for rendering, we will return michael@0: * false and if necessary destroy the device and/or swap chain. We will also michael@0: * schedule another composite so we get another go at rendering, thus we shouldn't michael@0: * miss a composite due to re-creating a device. michael@0: */ michael@0: virtual bool Ready() MOZ_OVERRIDE; michael@0: michael@0: /** michael@0: * Declare an offset to use when rendering layers. This will be ignored when michael@0: * rendering to a target instead of the screen. michael@0: */ michael@0: virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE michael@0: { michael@0: if (aOffset.x || aOffset.y) { michael@0: NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D9."); michael@0: } michael@0: // If the offset is 0, 0 that's okay. michael@0: } michael@0: michael@0: virtual TemporaryRef michael@0: CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; michael@0: private: michael@0: // ensure mSize is up to date with respect to mWidget michael@0: void EnsureSize(); michael@0: void SetSamplerForFilter(gfx::Filter aFilter); michael@0: void PaintToTarget(); michael@0: void SetMask(const EffectChain &aEffectChain, uint32_t aMaskTexture); michael@0: /** michael@0: * Ensure we have a swap chain and it is ready for rendering. michael@0: * Requires mDeviceManger to be non-null. michael@0: * Returns true if we have a working swap chain; false otherwise. michael@0: * If we cannot create or validate the swap chain due to a bad device manager, michael@0: * then the device will be destroyed and set mDeviceManager to null. We will michael@0: * schedule another composite if it is a good idea to try again or we need to michael@0: * recreate the device. michael@0: */ michael@0: bool EnsureSwapChain(); michael@0: michael@0: /** michael@0: * DeviceManagerD3D9 keeps a count of the number of times its device is michael@0: * reset or recreated. We keep a parallel count (mDeviceResetCount). It michael@0: * is possible that we miss a reset if it is 'caused' by another michael@0: * compositor (for another window). In which case we need to invalidate michael@0: * everything and render it all. This method checks the reset counts michael@0: * match and if not invalidates everything (a long comment on that in michael@0: * the cpp file). michael@0: */ michael@0: void CheckResetCount(); michael@0: michael@0: void ReportFailure(const nsACString &aMsg, HRESULT aCode); michael@0: michael@0: virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE michael@0: { michael@0: return gfx::ToIntSize(mSize); michael@0: } michael@0: michael@0: /* Device manager instance for this compositor */ michael@0: nsRefPtr mDeviceManager; michael@0: michael@0: /* Swap chain associated with this compositor */ michael@0: nsRefPtr mSwapChain; michael@0: michael@0: /* Widget associated with this layer manager */ michael@0: nsIWidget *mWidget; michael@0: michael@0: /* michael@0: * Context target, nullptr when drawing directly to our swap chain. michael@0: */ michael@0: RefPtr mTarget; michael@0: michael@0: RefPtr mDefaultRT; michael@0: RefPtr mCurrentRT; michael@0: michael@0: nsIntSize mSize; michael@0: michael@0: uint32_t mDeviceResetCount; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif