CompositableHost.h (4060B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef MOZILLA_GFX_BUFFERHOST_H 8 #define MOZILLA_GFX_BUFFERHOST_H 9 10 #include <stdint.h> // for uint64_t 11 #include <stdio.h> // for FILE 12 #include "gfxRect.h" // for gfxRect 13 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc 14 #include "mozilla/RefPtr.h" // for RefPtr, RefCounted, etc 15 // #include "mozilla/gfx/MatrixFwd.h" // for Matrix4x4 16 #include "mozilla/gfx/Polygon.h" // for Polygon 17 #include "mozilla/gfx/Rect.h" // for Rect 18 #include "mozilla/ipc/ProtocolUtils.h" 19 #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc 20 // #include "mozilla/layers/LayersTypes.h" // for LayerRenderState, etc 21 #include "mozilla/layers/LayersMessages.h" 22 #include "mozilla/layers/TextureHost.h" // for TextureHost 23 #include "nsCOMPtr.h" // for already_AddRefed 24 #include "nscore.h" // for nsACString 25 #include "Units.h" // for CSSToScreenScale 26 27 namespace mozilla { 28 29 namespace layers { 30 31 class WebRenderImageHost; 32 33 struct ImageCompositeNotificationInfo { 34 base::ProcessId mImageBridgeProcessId; 35 ImageCompositeNotification mNotification; 36 }; 37 38 struct AsyncCompositableRef { 39 AsyncCompositableRef() : mProcessId(base::kInvalidProcessId) {} 40 AsyncCompositableRef(base::ProcessId aProcessId, 41 const CompositableHandle& aHandle) 42 : mProcessId(aProcessId), mHandle(aHandle) {} 43 explicit operator bool() const { return !!mHandle; } 44 base::ProcessId mProcessId; 45 CompositableHandle mHandle; 46 }; 47 48 /** 49 * The compositor-side counterpart to CompositableClient. Responsible for 50 * updating textures and data about textures from IPC and how textures are 51 * composited (tiling, double buffering, etc.). 52 * 53 * Update (for images/canvases) and UpdateThebes (for Thebes) are called during 54 * the layers transaction to update the Compositbale's textures from the 55 * content side. The actual update (and any syncronous upload) is done by the 56 * TextureHost, but it is coordinated by the CompositableHost. 57 * 58 * Composite is called by the owning layer when it is composited. 59 * CompositableHost will use its TextureHost(s) and call Compositor::DrawQuad to 60 * do the actual rendering. 61 */ 62 class CompositableHost { 63 protected: 64 virtual ~CompositableHost(); 65 66 public: 67 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableHost) 68 explicit CompositableHost(const TextureInfo& aTextureInfo); 69 70 static already_AddRefed<CompositableHost> Create( 71 const TextureInfo& aTextureInfo); 72 73 virtual WebRenderImageHost* AsWebRenderImageHost() { return nullptr; } 74 75 virtual void Dump(std::stringstream& aStream, const char* aPrefix = "", 76 bool aDumpHtml = false) {} 77 static void DumpTextureHost(std::stringstream& aStream, 78 TextureHost* aTexture); 79 80 struct TimedTexture { 81 CompositableTextureHostRef mTexture; 82 TimeStamp mTimeStamp; 83 gfx::IntRect mPictureRect; 84 int32_t mFrameID; 85 int32_t mProducerID; 86 }; 87 virtual void UseTextureHost(const nsTArray<TimedTexture>& aTextures); 88 virtual void RemoveTextureHost(TextureHost* aTexture); 89 90 virtual void ClearImages(ClearImagesType aType) {} 91 92 const AsyncCompositableRef& GetAsyncRef() const { return mAsyncRef; } 93 void SetAsyncRef(const AsyncCompositableRef& aRef) { mAsyncRef = aRef; } 94 95 /// Called when shutting down the layer tree. 96 /// This is a good place to clear all potential gpu resources before the 97 /// widget is is destroyed. 98 virtual void CleanupResources() {} 99 100 virtual void OnReleased() {} 101 102 virtual uint32_t GetDroppedFrames() { return 0; } 103 104 const TextureInfo mTextureInfo; 105 106 protected: 107 AsyncCompositableRef mAsyncRef; 108 }; 109 110 } // namespace layers 111 } // namespace mozilla 112 113 #endif