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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef MOZILLA_GFX_COMPOSITORD3D9_H |
michael@0 | 7 | #define MOZILLA_GFX_COMPOSITORD3D9_H |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/gfx/2D.h" |
michael@0 | 10 | #include "gfx2DGlue.h" |
michael@0 | 11 | #include "mozilla/layers/Compositor.h" |
michael@0 | 12 | #include "mozilla/layers/TextureD3D9.h" |
michael@0 | 13 | #include "DeviceManagerD3D9.h" |
michael@0 | 14 | |
michael@0 | 15 | class nsWidget; |
michael@0 | 16 | |
michael@0 | 17 | namespace mozilla { |
michael@0 | 18 | namespace layers { |
michael@0 | 19 | |
michael@0 | 20 | class CompositorD3D9 : public Compositor |
michael@0 | 21 | { |
michael@0 | 22 | public: |
michael@0 | 23 | CompositorD3D9(PCompositorParent* aParent, nsIWidget *aWidget); |
michael@0 | 24 | ~CompositorD3D9(); |
michael@0 | 25 | |
michael@0 | 26 | virtual bool Initialize() MOZ_OVERRIDE; |
michael@0 | 27 | virtual void Destroy() MOZ_OVERRIDE {} |
michael@0 | 28 | |
michael@0 | 29 | virtual TextureFactoryIdentifier |
michael@0 | 30 | GetTextureFactoryIdentifier() MOZ_OVERRIDE; |
michael@0 | 31 | |
michael@0 | 32 | virtual bool CanUseCanvasLayerForSize(const gfx::IntSize &aSize) MOZ_OVERRIDE; |
michael@0 | 33 | virtual int32_t GetMaxTextureSize() const MOZ_FINAL; |
michael@0 | 34 | |
michael@0 | 35 | virtual void SetTargetContext(gfx::DrawTarget *aTarget) MOZ_OVERRIDE |
michael@0 | 36 | { |
michael@0 | 37 | mTarget = aTarget; |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | virtual void MakeCurrent(MakeCurrentFlags aFlags = 0) MOZ_OVERRIDE {} |
michael@0 | 41 | |
michael@0 | 42 | virtual TemporaryRef<CompositingRenderTarget> |
michael@0 | 43 | CreateRenderTarget(const gfx::IntRect &aRect, |
michael@0 | 44 | SurfaceInitMode aInit) MOZ_OVERRIDE; |
michael@0 | 45 | |
michael@0 | 46 | virtual TemporaryRef<CompositingRenderTarget> |
michael@0 | 47 | CreateRenderTargetFromSource(const gfx::IntRect &aRect, |
michael@0 | 48 | const CompositingRenderTarget *aSource, |
michael@0 | 49 | const gfx::IntPoint &aSourcePoint) MOZ_OVERRIDE; |
michael@0 | 50 | |
michael@0 | 51 | virtual void SetRenderTarget(CompositingRenderTarget *aSurface); |
michael@0 | 52 | virtual CompositingRenderTarget* GetCurrentRenderTarget() const MOZ_OVERRIDE |
michael@0 | 53 | { |
michael@0 | 54 | return mCurrentRT; |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | virtual void SetDestinationSurfaceSize(const gfx::IntSize& aSize) MOZ_OVERRIDE {} |
michael@0 | 58 | |
michael@0 | 59 | virtual void ClearRect(const gfx::Rect& aRect) MOZ_OVERRIDE; |
michael@0 | 60 | |
michael@0 | 61 | virtual void DrawQuad(const gfx::Rect &aRect, |
michael@0 | 62 | const gfx::Rect &aClipRect, |
michael@0 | 63 | const EffectChain &aEffectChain, |
michael@0 | 64 | gfx::Float aOpacity, |
michael@0 | 65 | const gfx::Matrix4x4 &aTransform) MOZ_OVERRIDE; |
michael@0 | 66 | |
michael@0 | 67 | virtual void BeginFrame(const nsIntRegion& aInvalidRegion, |
michael@0 | 68 | const gfx::Rect *aClipRectIn, |
michael@0 | 69 | const gfx::Matrix& aTransform, |
michael@0 | 70 | const gfx::Rect& aRenderBounds, |
michael@0 | 71 | gfx::Rect *aClipRectOut = nullptr, |
michael@0 | 72 | gfx::Rect *aRenderBoundsOut = nullptr) MOZ_OVERRIDE; |
michael@0 | 73 | |
michael@0 | 74 | virtual void EndFrame() MOZ_OVERRIDE; |
michael@0 | 75 | |
michael@0 | 76 | virtual void EndFrameForExternalComposition(const gfx::Matrix& aTransform) MOZ_OVERRIDE {} |
michael@0 | 77 | |
michael@0 | 78 | virtual void AbortFrame() MOZ_OVERRIDE {} |
michael@0 | 79 | |
michael@0 | 80 | virtual void PrepareViewport(const gfx::IntSize& aSize, |
michael@0 | 81 | const gfx::Matrix& aWorldTransform) MOZ_OVERRIDE; |
michael@0 | 82 | |
michael@0 | 83 | virtual bool SupportsPartialTextureUpdate() MOZ_OVERRIDE{ return true; } |
michael@0 | 84 | |
michael@0 | 85 | #ifdef MOZ_DUMP_PAINTING |
michael@0 | 86 | virtual const char* Name() const MOZ_OVERRIDE { return "Direct3D9"; } |
michael@0 | 87 | #endif |
michael@0 | 88 | |
michael@0 | 89 | virtual LayersBackend GetBackendType() const MOZ_OVERRIDE { |
michael@0 | 90 | return LayersBackend::LAYERS_D3D9; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | virtual nsIWidget* GetWidget() const MOZ_OVERRIDE { return mWidget; } |
michael@0 | 94 | |
michael@0 | 95 | IDirect3DDevice9* device() const |
michael@0 | 96 | { |
michael@0 | 97 | return mDeviceManager |
michael@0 | 98 | ? mDeviceManager->device() |
michael@0 | 99 | : nullptr; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * Returns true if the Compositor is ready to go. |
michael@0 | 104 | * D3D9 devices can be awkward and there is a bunch of logic around |
michael@0 | 105 | * resetting/recreating devices and swap chains. That is handled by this method. |
michael@0 | 106 | * If we don't have a device and swap chain ready for rendering, we will return |
michael@0 | 107 | * false and if necessary destroy the device and/or swap chain. We will also |
michael@0 | 108 | * schedule another composite so we get another go at rendering, thus we shouldn't |
michael@0 | 109 | * miss a composite due to re-creating a device. |
michael@0 | 110 | */ |
michael@0 | 111 | virtual bool Ready() MOZ_OVERRIDE; |
michael@0 | 112 | |
michael@0 | 113 | /** |
michael@0 | 114 | * Declare an offset to use when rendering layers. This will be ignored when |
michael@0 | 115 | * rendering to a target instead of the screen. |
michael@0 | 116 | */ |
michael@0 | 117 | virtual void SetScreenRenderOffset(const ScreenPoint& aOffset) MOZ_OVERRIDE |
michael@0 | 118 | { |
michael@0 | 119 | if (aOffset.x || aOffset.y) { |
michael@0 | 120 | NS_RUNTIMEABORT("SetScreenRenderOffset not supported by CompositorD3D9."); |
michael@0 | 121 | } |
michael@0 | 122 | // If the offset is 0, 0 that's okay. |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | virtual TemporaryRef<DataTextureSource> |
michael@0 | 126 | CreateDataTextureSource(TextureFlags aFlags = 0) MOZ_OVERRIDE; |
michael@0 | 127 | private: |
michael@0 | 128 | // ensure mSize is up to date with respect to mWidget |
michael@0 | 129 | void EnsureSize(); |
michael@0 | 130 | void SetSamplerForFilter(gfx::Filter aFilter); |
michael@0 | 131 | void PaintToTarget(); |
michael@0 | 132 | void SetMask(const EffectChain &aEffectChain, uint32_t aMaskTexture); |
michael@0 | 133 | /** |
michael@0 | 134 | * Ensure we have a swap chain and it is ready for rendering. |
michael@0 | 135 | * Requires mDeviceManger to be non-null. |
michael@0 | 136 | * Returns true if we have a working swap chain; false otherwise. |
michael@0 | 137 | * If we cannot create or validate the swap chain due to a bad device manager, |
michael@0 | 138 | * then the device will be destroyed and set mDeviceManager to null. We will |
michael@0 | 139 | * schedule another composite if it is a good idea to try again or we need to |
michael@0 | 140 | * recreate the device. |
michael@0 | 141 | */ |
michael@0 | 142 | bool EnsureSwapChain(); |
michael@0 | 143 | |
michael@0 | 144 | /** |
michael@0 | 145 | * DeviceManagerD3D9 keeps a count of the number of times its device is |
michael@0 | 146 | * reset or recreated. We keep a parallel count (mDeviceResetCount). It |
michael@0 | 147 | * is possible that we miss a reset if it is 'caused' by another |
michael@0 | 148 | * compositor (for another window). In which case we need to invalidate |
michael@0 | 149 | * everything and render it all. This method checks the reset counts |
michael@0 | 150 | * match and if not invalidates everything (a long comment on that in |
michael@0 | 151 | * the cpp file). |
michael@0 | 152 | */ |
michael@0 | 153 | void CheckResetCount(); |
michael@0 | 154 | |
michael@0 | 155 | void ReportFailure(const nsACString &aMsg, HRESULT aCode); |
michael@0 | 156 | |
michael@0 | 157 | virtual gfx::IntSize GetWidgetSize() const MOZ_OVERRIDE |
michael@0 | 158 | { |
michael@0 | 159 | return gfx::ToIntSize(mSize); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | /* Device manager instance for this compositor */ |
michael@0 | 163 | nsRefPtr<DeviceManagerD3D9> mDeviceManager; |
michael@0 | 164 | |
michael@0 | 165 | /* Swap chain associated with this compositor */ |
michael@0 | 166 | nsRefPtr<SwapChainD3D9> mSwapChain; |
michael@0 | 167 | |
michael@0 | 168 | /* Widget associated with this layer manager */ |
michael@0 | 169 | nsIWidget *mWidget; |
michael@0 | 170 | |
michael@0 | 171 | /* |
michael@0 | 172 | * Context target, nullptr when drawing directly to our swap chain. |
michael@0 | 173 | */ |
michael@0 | 174 | RefPtr<gfx::DrawTarget> mTarget; |
michael@0 | 175 | |
michael@0 | 176 | RefPtr<CompositingRenderTargetD3D9> mDefaultRT; |
michael@0 | 177 | RefPtr<CompositingRenderTargetD3D9> mCurrentRT; |
michael@0 | 178 | |
michael@0 | 179 | nsIntSize mSize; |
michael@0 | 180 | |
michael@0 | 181 | uint32_t mDeviceResetCount; |
michael@0 | 182 | }; |
michael@0 | 183 | |
michael@0 | 184 | } |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | #endif |