michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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_LAYERS_COMPOSITABLEFORWARDER michael@0: #define MOZILLA_LAYERS_COMPOSITABLEFORWARDER michael@0: michael@0: #include // for int32_t, uint64_t michael@0: #include "gfxTypes.h" michael@0: #include "mozilla/Attributes.h" // for MOZ_OVERRIDE michael@0: #include "mozilla/layers/CompositorTypes.h" michael@0: #include "mozilla/layers/ISurfaceAllocator.h" // for ISurfaceAllocator michael@0: #include "mozilla/layers/LayersTypes.h" // for LayersBackend michael@0: #include "mozilla/layers/TextureClient.h" // for TextureClient michael@0: #include "nsRegion.h" // for nsIntRegion michael@0: michael@0: struct nsIntPoint; michael@0: struct nsIntRect; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class CompositableClient; michael@0: class TextureFactoryIdentifier; michael@0: class SurfaceDescriptor; michael@0: class SurfaceDescriptorTiles; michael@0: class ThebesBufferData; michael@0: class ClientTiledLayerBuffer; michael@0: class PTextureChild; michael@0: michael@0: /** michael@0: * A transaction is a set of changes that happenned on the content side, that michael@0: * should be sent to the compositor side. michael@0: * CompositableForwarder is an interface to manage a transaction of michael@0: * compositable objetcs. michael@0: * michael@0: * ShadowLayerForwarder is an example of a CompositableForwarder (that can michael@0: * additionally forward modifications of the Layer tree). michael@0: * ImageBridgeChild is another CompositableForwarder. michael@0: */ michael@0: class CompositableForwarder : public ISurfaceAllocator michael@0: { michael@0: public: michael@0: michael@0: CompositableForwarder() michael@0: : mSerial(++sSerialCounter) michael@0: {} michael@0: michael@0: /** michael@0: * Setup the IPDL actor for aCompositable to be part of layers michael@0: * transactions. michael@0: */ michael@0: virtual void Connect(CompositableClient* aCompositable) = 0; michael@0: michael@0: /** michael@0: * Notify the CompositableHost that it should create host-side-only michael@0: * texture(s), that we will update incrementally using UpdateTextureIncremental. michael@0: */ michael@0: virtual void CreatedIncrementalBuffer(CompositableClient* aCompositable, michael@0: const TextureInfo& aTextureInfo, michael@0: const nsIntRect& aBufferRect) = 0; michael@0: michael@0: /** michael@0: * Tell the CompositableHost on the compositor side what TiledLayerBuffer to michael@0: * use for the next composition. michael@0: */ michael@0: virtual void UseTiledLayerBuffer(CompositableClient* aCompositable, michael@0: const SurfaceDescriptorTiles& aTiledDescriptor) = 0; michael@0: michael@0: /** michael@0: * Create a TextureChild/Parent pair as as well as the TextureHost on the parent side. michael@0: */ michael@0: virtual PTextureChild* CreateTexture(const SurfaceDescriptor& aSharedData, TextureFlags aFlags) = 0; michael@0: michael@0: /** michael@0: * Communicate to the compositor that aRegion in the texture identified by michael@0: * aCompositable and aIdentifier has been updated to aThebesBuffer. michael@0: */ michael@0: virtual void UpdateTextureRegion(CompositableClient* aCompositable, michael@0: const ThebesBufferData& aThebesBufferData, michael@0: const nsIntRegion& aUpdatedRegion) = 0; michael@0: michael@0: /** michael@0: * Notify the compositor to update aTextureId using aDescriptor, and take michael@0: * ownership of aDescriptor. michael@0: * michael@0: * aDescriptor only contains the pixels for aUpdatedRegion, and is relative michael@0: * to aUpdatedRegion.TopLeft(). michael@0: * michael@0: * aBufferRect/aBufferRotation define the new valid region contained michael@0: * within the texture after the update has been applied. michael@0: */ michael@0: virtual void UpdateTextureIncremental(CompositableClient* aCompositable, michael@0: TextureIdentifier aTextureId, michael@0: SurfaceDescriptor& aDescriptor, michael@0: const nsIntRegion& aUpdatedRegion, michael@0: const nsIntRect& aBufferRect, michael@0: const nsIntPoint& aBufferRotation) = 0; michael@0: michael@0: /** michael@0: * Communicate the picture rect of a YUV image in aLayer to the compositor michael@0: */ michael@0: virtual void UpdatePictureRect(CompositableClient* aCompositable, michael@0: const nsIntRect& aRect) = 0; michael@0: michael@0: /** michael@0: * Tell the CompositableHost on the compositor side to remove the texture. michael@0: * This function does not delete the TextureHost corresponding to the michael@0: * TextureClient passed in parameter. michael@0: */ michael@0: virtual void RemoveTextureFromCompositable(CompositableClient* aCompositable, michael@0: TextureClient* aTexture) = 0; michael@0: michael@0: /** michael@0: * Tell the compositor side to delete the TextureHost corresponding to the michael@0: * TextureClient passed in parameter. michael@0: */ michael@0: virtual void RemoveTexture(TextureClient* aTexture) = 0; michael@0: michael@0: /** michael@0: * Holds a reference to a TextureClient until after the next michael@0: * compositor transaction, and then drops it. michael@0: */ michael@0: virtual void HoldUntilTransaction(TextureClient* aClient) michael@0: { michael@0: if (aClient) { michael@0: mTexturesToRemove.AppendElement(aClient); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Forcibly remove texture data from TextureClient michael@0: * This function needs to be called after a tansaction with Compositor. michael@0: */ michael@0: virtual void RemoveTexturesIfNecessary() michael@0: { michael@0: mTexturesToRemove.Clear(); michael@0: } michael@0: michael@0: /** michael@0: * Tell the CompositableHost on the compositor side what texture to use for michael@0: * the next composition. michael@0: */ michael@0: virtual void UseTexture(CompositableClient* aCompositable, michael@0: TextureClient* aClient) = 0; michael@0: virtual void UseComponentAlphaTextures(CompositableClient* aCompositable, michael@0: TextureClient* aClientOnBlack, michael@0: TextureClient* aClientOnWhite) = 0; michael@0: michael@0: /** michael@0: * Tell the compositor side that the shared data has been modified so that michael@0: * it can react accordingly (upload textures, etc.). michael@0: */ michael@0: virtual void UpdatedTexture(CompositableClient* aCompositable, michael@0: TextureClient* aTexture, michael@0: nsIntRegion* aRegion) = 0; michael@0: michael@0: void IdentifyTextureHost(const TextureFactoryIdentifier& aIdentifier); michael@0: michael@0: virtual int32_t GetMaxTextureSize() const MOZ_OVERRIDE michael@0: { michael@0: return mTextureFactoryIdentifier.mMaxTextureSize; michael@0: } michael@0: michael@0: bool IsOnCompositorSide() const MOZ_OVERRIDE { return false; } michael@0: michael@0: /** michael@0: * Returns the type of backend that is used off the main thread. michael@0: * We only don't allow changing the backend type at runtime so this value can michael@0: * be queried once and will not change until Gecko is restarted. michael@0: */ michael@0: virtual LayersBackend GetCompositorBackendType() const MOZ_OVERRIDE michael@0: { michael@0: return mTextureFactoryIdentifier.mParentBackend; michael@0: } michael@0: michael@0: bool SupportsTextureBlitting() const michael@0: { michael@0: return mTextureFactoryIdentifier.mSupportsTextureBlitting; michael@0: } michael@0: michael@0: bool SupportsPartialUploads() const michael@0: { michael@0: return mTextureFactoryIdentifier.mSupportsPartialUploads; michael@0: } michael@0: michael@0: const TextureFactoryIdentifier& GetTextureFactoryIdentifier() const michael@0: { michael@0: return mTextureFactoryIdentifier; michael@0: } michael@0: michael@0: int32_t GetSerial() { return mSerial; } michael@0: michael@0: protected: michael@0: TextureFactoryIdentifier mTextureFactoryIdentifier; michael@0: nsTArray > mTexturesToRemove; michael@0: const int32_t mSerial; michael@0: static mozilla::Atomic sSerialCounter; michael@0: }; michael@0: michael@0: } // namespace michael@0: } // namespace michael@0: michael@0: #endif