1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/d3d9/CompositorD3D9.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,187 @@ 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_COMPOSITORD3D9_H 1.10 +#define MOZILLA_GFX_COMPOSITORD3D9_H 1.11 + 1.12 +#include "mozilla/gfx/2D.h" 1.13 +#include "gfx2DGlue.h" 1.14 +#include "mozilla/layers/Compositor.h" 1.15 +#include "mozilla/layers/TextureD3D9.h" 1.16 +#include "DeviceManagerD3D9.h" 1.17 + 1.18 +class nsWidget; 1.19 + 1.20 +namespace mozilla { 1.21 +namespace layers { 1.22 + 1.23 +class CompositorD3D9 : public Compositor 1.24 +{ 1.25 +public: 1.26 + CompositorD3D9(PCompositorParent* aParent, nsIWidget *aWidget); 1.27 + ~CompositorD3D9(); 1.28 + 1.29 + virtual bool Initialize() MOZ_OVERRIDE; 1.30 + virtual void Destroy() MOZ_OVERRIDE {} 1.31 + 1.32 + virtual TextureFactoryIdentifier 1.33 + GetTextureFactoryIdentifier() MOZ_OVERRIDE; 1.34 + 1.35 + virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE; 1.36 + virtual int32_t GetMaxTextureSize() const MOZ_FINAL; 1.37 + 1.38 + virtual void SetTargetContext(gfx::DrawTarget *aTarget) MOZ_OVERRIDE 1.39 + { 1.40 + mTarget = aTarget; 1.41 + } 1.42 + 1.43 + virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {} 1.44 + 1.45 + virtual TemporaryRef<CompositingRenderTarget> 1.46 + CreateRenderTarget(const gfx::IntRect &aRect, 1.47 + SurfaceInitMode aInit) MOZ_OVERRIDE; 1.48 + 1.49 + virtual TemporaryRef<CompositingRenderTarget> 1.50 + CreateRenderTargetFromSource(const gfx::IntRect &aRect, 1.51 + const CompositingRenderTarget *aSource, 1.52 + const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE; 1.53 + 1.54 + virtual void SetRenderTarget(CompositingRenderTarget *aSurface); 1.55 + virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE 1.56 + { 1.57 + return mCurrentRT; 1.58 + } 1.59 + 1.60 + virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {} 1.61 + 1.62 + virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE; 1.63 + 1.64 + virtual void DrawQuad(const gfx::Rect &aRect, 1.65 + const gfx::Rect &aClipRect, 1.66 + const EffectChain &aEffectChain, 1.67 + gfx::Float aOpacity, 1.68 + const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; 1.69 + 1.70 + virtual void BeginFrame(const nsIntRegion& aInvalidRegion, 1.71 + const gfx::Rect *aClipRectIn, 1.72 + const gfx::Matrix& aTransform, 1.73 + const gfx::Rect& aRenderBounds, 1.74 + gfx::Rect *aClipRectOut = nullptr, 1.75 + gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; 1.76 + 1.77 + virtual void EndFrame() MOZ_OVERRIDE; 1.78 + 1.79 + virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {} 1.80 + 1.81 + virtual void AbortFrame() MOZ_OVERRIDE {} 1.82 + 1.83 + virtual void PrepareViewport(const gfx::IntSize& aSize, 1.84 + const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE; 1.85 + 1.86 + virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE{ return true; } 1.87 + 1.88 +#ifdef MOZ_DUMP_PAINTING 1.89 + virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D9"; } 1.90 +#endif 1.91 + 1.92 + virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { 1.93 + return LayersBackend::LAYERS_D3D9; 1.94 + } 1.95 + 1.96 + virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } 1.97 + 1.98 + IDirect3DDevice9* device() const 1.99 + { 1.100 + return mDeviceManager 1.101 + ? mDeviceManager->device() 1.102 + : nullptr; 1.103 + } 1.104 + 1.105 + /** 1.106 + * Returns true if the Compositor is ready to go. 1.107 + * D3D9 devices can be awkward and there is a bunch of logic around 1.108 + * resetting/recreating devices and swap chains. That is handled by this method. 1.109 + * If we don't have a device and swap chain ready for rendering, we will return 1.110 + * false and if necessary destroy the device and/or swap chain. We will also 1.111 + * schedule another composite so we get another go at rendering, thus we shouldn't 1.112 + * miss a composite due to re-creating a device. 1.113 + */ 1.114 + virtual bool Ready() MOZ_OVERRIDE; 1.115 + 1.116 + /** 1.117 + * Declare an offset to use when rendering layers. This will be ignored when 1.118 + * rendering to a target instead of the screen. 1.119 + */ 1.120 + virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE 1.121 + { 1.122 + if (aOffset.x || aOffset.y) { 1.123 + NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D9."); 1.124 + } 1.125 + // If the offset is 0, 0 that's okay. 1.126 + } 1.127 + 1.128 + virtual TemporaryRef<DataTextureSource> 1.129 + CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; 1.130 +private: 1.131 + // ensure mSize is up to date with respect to mWidget 1.132 + void EnsureSize(); 1.133 + void SetSamplerForFilter(gfx::Filter aFilter); 1.134 + void PaintToTarget(); 1.135 + void SetMask(const EffectChain &aEffectChain, uint32_t aMaskTexture); 1.136 + /** 1.137 + * Ensure we have a swap chain and it is ready for rendering. 1.138 + * Requires mDeviceManger to be non-null. 1.139 + * Returns true if we have a working swap chain; false otherwise. 1.140 + * If we cannot create or validate the swap chain due to a bad device manager, 1.141 + * then the device will be destroyed and set mDeviceManager to null. We will 1.142 + * schedule another composite if it is a good idea to try again or we need to 1.143 + * recreate the device. 1.144 + */ 1.145 + bool EnsureSwapChain(); 1.146 + 1.147 + /** 1.148 + * DeviceManagerD3D9 keeps a count of the number of times its device is 1.149 + * reset or recreated. We keep a parallel count (mDeviceResetCount). It 1.150 + * is possible that we miss a reset if it is 'caused' by another 1.151 + * compositor (for another window). In which case we need to invalidate 1.152 + * everything and render it all. This method checks the reset counts 1.153 + * match and if not invalidates everything (a long comment on that in 1.154 + * the cpp file). 1.155 + */ 1.156 + void CheckResetCount(); 1.157 + 1.158 + void ReportFailure(const nsACString &aMsg, HRESULT aCode); 1.159 + 1.160 + virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE 1.161 + { 1.162 + return gfx::ToIntSize(mSize); 1.163 + } 1.164 + 1.165 + /* Device manager instance for this compositor */ 1.166 + nsRefPtr<DeviceManagerD3D9> mDeviceManager; 1.167 + 1.168 + /* Swap chain associated with this compositor */ 1.169 + nsRefPtr<SwapChainD3D9> mSwapChain; 1.170 + 1.171 + /* Widget associated with this layer manager */ 1.172 + nsIWidget *mWidget; 1.173 + 1.174 + /* 1.175 + * Context target, nullptr when drawing directly to our swap chain. 1.176 + */ 1.177 + RefPtr<gfx::DrawTarget> mTarget; 1.178 + 1.179 + RefPtr<CompositingRenderTargetD3D9> mDefaultRT; 1.180 + RefPtr<CompositingRenderTargetD3D9> mCurrentRT; 1.181 + 1.182 + nsIntSize mSize; 1.183 + 1.184 + uint32_t mDeviceResetCount; 1.185 +}; 1.186 + 1.187 +} 1.188 +} 1.189 + 1.190 +#endif