1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/ipc/CompositableForwarder.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,206 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef MOZILLA_LAYERS_COMPOSITABLEFORWARDER 1.11 +#define MOZILLA_LAYERS_COMPOSITABLEFORWARDER 1.12 + 1.13 +#include <stdint.h> // for int32_t, uint64_t 1.14 +#include "gfxTypes.h" 1.15 +#include "mozilla/Attributes.h" // for MOZ_OVERRIDE 1.16 +#include "mozilla/layers/CompositorTypes.h" 1.17 +#include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator 1.18 +#include "mozilla/layers/LayersTypes.h" // for LayersBackend 1.19 +#include "mozilla/layers/TextureClient.h" // for TextureClient 1.20 +#include "nsRegion.h" // for nsIntRegion 1.21 + 1.22 +struct nsIntPoint; 1.23 +struct nsIntRect; 1.24 + 1.25 +namespace mozilla { 1.26 +namespace layers { 1.27 + 1.28 +class CompositableClient; 1.29 +class TextureFactoryIdentifier; 1.30 +class SurfaceDescriptor; 1.31 +class SurfaceDescriptorTiles; 1.32 +class ThebesBufferData; 1.33 +class ClientTiledLayerBuffer; 1.34 +class PTextureChild; 1.35 + 1.36 +/** 1.37 + * A transaction is a set of changes that happenned on the content side, that 1.38 + * should be sent to the compositor side. 1.39 + * CompositableForwarder is an interface to manage a transaction of 1.40 + * compositable objetcs. 1.41 + * 1.42 + * ShadowLayerForwarder is an example of a CompositableForwarder (that can 1.43 + * additionally forward modifications of the Layer tree). 1.44 + * ImageBridgeChild is another CompositableForwarder. 1.45 + */ 1.46 +class CompositableForwarder : public ISurfaceAllocator 1.47 +{ 1.48 +public: 1.49 + 1.50 + CompositableForwarder() 1.51 + : mSerial(++sSerialCounter) 1.52 + {} 1.53 + 1.54 + /** 1.55 + * Setup the IPDL actor for aCompositable to be part of layers 1.56 + * transactions. 1.57 + */ 1.58 + virtual void Connect(CompositableClient* aCompositable) = 0; 1.59 + 1.60 + /** 1.61 + * Notify the CompositableHost that it should create host-side-only 1.62 + * texture(s), that we will update incrementally using UpdateTextureIncremental. 1.63 + */ 1.64 + virtual void CreatedIncrementalBuffer(CompositableClient* aCompositable, 1.65 + const TextureInfo& aTextureInfo, 1.66 + const nsIntRect& aBufferRect) = 0; 1.67 + 1.68 + /** 1.69 + * Tell the CompositableHost on the compositor side what TiledLayerBuffer to 1.70 + * use for the next composition. 1.71 + */ 1.72 + virtual void UseTiledLayerBuffer(CompositableClient* aCompositable, 1.73 + const SurfaceDescriptorTiles& aTiledDescriptor) = 0; 1.74 + 1.75 + /** 1.76 + * Create a TextureChild/Parent pair as as well as the TextureHost on the parent side. 1.77 + */ 1.78 + virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData, TextureFlags aFlags) = 0; 1.79 + 1.80 + /** 1.81 + * Communicate to the compositor that aRegion in the texture identified by 1.82 + * aCompositable and aIdentifier has been updated to aThebesBuffer. 1.83 + */ 1.84 + virtual void UpdateTextureRegion(CompositableClient* aCompositable, 1.85 + const ThebesBufferData& aThebesBufferData, 1.86 + const nsIntRegion& aUpdatedRegion) = 0; 1.87 + 1.88 + /** 1.89 + * Notify the compositor to update aTextureId using aDescriptor, and take 1.90 + * ownership of aDescriptor. 1.91 + * 1.92 + * aDescriptor only contains the pixels for aUpdatedRegion, and is relative 1.93 + * to aUpdatedRegion.TopLeft(). 1.94 + * 1.95 + * aBufferRect/aBufferRotation define the new valid region contained 1.96 + * within the texture after the update has been applied. 1.97 + */ 1.98 + virtual void UpdateTextureIncremental(CompositableClient* aCompositable, 1.99 + TextureIdentifier aTextureId, 1.100 + SurfaceDescriptor& aDescriptor, 1.101 + const nsIntRegion& aUpdatedRegion, 1.102 + const nsIntRect& aBufferRect, 1.103 + const nsIntPoint& aBufferRotation) = 0; 1.104 + 1.105 + /** 1.106 + * Communicate the picture rect of a YUV image in aLayer to the compositor 1.107 + */ 1.108 + virtual void UpdatePictureRect(CompositableClient* aCompositable, 1.109 + const nsIntRect& aRect) = 0; 1.110 + 1.111 + /** 1.112 + * Tell the CompositableHost on the compositor side to remove the texture. 1.113 + * This function does not delete the TextureHost corresponding to the 1.114 + * TextureClient passed in parameter. 1.115 + */ 1.116 + virtual void RemoveTextureFromCompositable(CompositableClient* aCompositable, 1.117 + TextureClient* aTexture) = 0; 1.118 + 1.119 + /** 1.120 + * Tell the compositor side to delete the TextureHost corresponding to the 1.121 + * TextureClient passed in parameter. 1.122 + */ 1.123 + virtual void RemoveTexture(TextureClient* aTexture) = 0; 1.124 + 1.125 + /** 1.126 + * Holds a reference to a TextureClient until after the next 1.127 + * compositor transaction, and then drops it. 1.128 + */ 1.129 + virtual void HoldUntilTransaction(TextureClient* aClient) 1.130 + { 1.131 + if (aClient) { 1.132 + mTexturesToRemove.AppendElement(aClient); 1.133 + } 1.134 + } 1.135 + 1.136 + /** 1.137 + * Forcibly remove texture data from TextureClient 1.138 + * This function needs to be called after a tansaction with Compositor. 1.139 + */ 1.140 + virtual void RemoveTexturesIfNecessary() 1.141 + { 1.142 + mTexturesToRemove.Clear(); 1.143 + } 1.144 + 1.145 + /** 1.146 + * Tell the CompositableHost on the compositor side what texture to use for 1.147 + * the next composition. 1.148 + */ 1.149 + virtual void UseTexture(CompositableClient* aCompositable, 1.150 + TextureClient* aClient) = 0; 1.151 + virtual void UseComponentAlphaTextures(CompositableClient* aCompositable, 1.152 + TextureClient* aClientOnBlack, 1.153 + TextureClient* aClientOnWhite) = 0; 1.154 + 1.155 + /** 1.156 + * Tell the compositor side that the shared data has been modified so that 1.157 + * it can react accordingly (upload textures, etc.). 1.158 + */ 1.159 + virtual void UpdatedTexture(CompositableClient* aCompositable, 1.160 + TextureClient* aTexture, 1.161 + nsIntRegion* aRegion) = 0; 1.162 + 1.163 + void IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier); 1.164 + 1.165 + virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE 1.166 + { 1.167 + return mTextureFactoryIdentifier.mMaxTextureSize; 1.168 + } 1.169 + 1.170 + bool IsOnCompositorSide() const MOZ_OVERRIDE { return false; } 1.171 + 1.172 + /** 1.173 + * Returns the type of backend that is used off the main thread. 1.174 + * We only don't allow changing the backend type at runtime so this value can 1.175 + * be queried once and will not change until Gecko is restarted. 1.176 + */ 1.177 + virtual LayersBackend GetCompositorBackendType() const MOZ_OVERRIDE 1.178 + { 1.179 + return mTextureFactoryIdentifier.mParentBackend; 1.180 + } 1.181 + 1.182 + bool SupportsTextureBlitting() const 1.183 + { 1.184 + return mTextureFactoryIdentifier.mSupportsTextureBlitting; 1.185 + } 1.186 + 1.187 + bool SupportsPartialUploads() const 1.188 + { 1.189 + return mTextureFactoryIdentifier.mSupportsPartialUploads; 1.190 + } 1.191 + 1.192 + const TextureFactoryIdentifier& GetTextureFactoryIdentifier() const 1.193 + { 1.194 + return mTextureFactoryIdentifier; 1.195 + } 1.196 + 1.197 + int32_t GetSerial() { return mSerial; } 1.198 + 1.199 +protected: 1.200 + TextureFactoryIdentifier mTextureFactoryIdentifier; 1.201 + nsTArray<RefPtr<TextureClient> > mTexturesToRemove; 1.202 + const int32_t mSerial; 1.203 + static mozilla::Atomic<int32_t> sSerialCounter; 1.204 +}; 1.205 + 1.206 +} // namespace 1.207 +} // namespace 1.208 + 1.209 +#endif