michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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_GFX_IMAGECLIENT_H michael@0: #define MOZILLA_GFX_IMAGECLIENT_H michael@0: michael@0: #include // for uint32_t, uint64_t michael@0: #include // for int32_t michael@0: #include "mozilla/Attributes.h" // for MOZ_OVERRIDE michael@0: #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef michael@0: #include "mozilla/gfx/Types.h" // for SurfaceFormat michael@0: #include "mozilla/layers/CompositableClient.h" // for CompositableClient michael@0: #include "mozilla/layers/CompositorTypes.h" // for CompositableType, etc michael@0: #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor michael@0: #include "mozilla/layers/TextureClient.h" // for TextureClient, etc michael@0: #include "mozilla/mozalloc.h" // for operator delete michael@0: #include "nsCOMPtr.h" // for already_AddRefed michael@0: #include "nsRect.h" // for nsIntRect michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: class CompositableForwarder; michael@0: class Image; michael@0: class ImageContainer; michael@0: class ShadowableLayer; michael@0: michael@0: /** michael@0: * Image clients are used by basic image layers on the content thread, they michael@0: * always match with an ImageHost on the compositor thread. See michael@0: * CompositableClient.h for information on connecting clients to hosts. michael@0: */ michael@0: class ImageClient : public CompositableClient michael@0: { michael@0: public: michael@0: /** michael@0: * Creates, configures, and returns a new image client. If necessary, a michael@0: * message will be sent to the compositor to create a corresponding image michael@0: * host. michael@0: */ michael@0: static TemporaryRef CreateImageClient(CompositableType aImageHostType, michael@0: CompositableForwarder* aFwd, michael@0: TextureFlags aFlags); michael@0: michael@0: virtual ~ImageClient() {} michael@0: michael@0: /** michael@0: * Update this ImageClient from aContainer in aLayer michael@0: * returns false if this is the wrong kind of ImageClient for aContainer. michael@0: * Note that returning true does not necessarily imply success michael@0: */ michael@0: virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0; michael@0: michael@0: /** michael@0: * The picture rect is the area of the texture which makes up the image. That michael@0: * is, the area that should be composited. In texture space. michael@0: */ michael@0: virtual void UpdatePictureRect(nsIntRect aPictureRect); michael@0: michael@0: virtual already_AddRefed CreateImage(ImageFormat aFormat) = 0; michael@0: michael@0: /** michael@0: * Synchronously remove all the textures used by the image client. michael@0: */ michael@0: virtual void FlushAllImages(bool aExceptFront) {} michael@0: michael@0: protected: michael@0: ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags, michael@0: CompositableType aType); michael@0: michael@0: CompositableType mType; michael@0: int32_t mLastPaintedImageSerial; michael@0: nsIntRect mPictureRect; michael@0: }; michael@0: michael@0: /** michael@0: * An image client which uses a single texture client. michael@0: */ michael@0: class ImageClientSingle : public ImageClient michael@0: { michael@0: public: michael@0: ImageClientSingle(CompositableForwarder* aFwd, michael@0: TextureFlags aFlags, michael@0: CompositableType aType); michael@0: michael@0: virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags); michael@0: michael@0: virtual void OnDetach() MOZ_OVERRIDE; michael@0: michael@0: virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE; michael@0: michael@0: virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE; michael@0: michael@0: virtual already_AddRefed CreateImage(ImageFormat aFormat) MOZ_OVERRIDE; michael@0: michael@0: virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: virtual bool UpdateImageInternal(ImageContainer* aContainer, uint32_t aContentFlags, bool* aIsSwapped); michael@0: michael@0: protected: michael@0: RefPtr mFrontBuffer; michael@0: }; michael@0: michael@0: /** michael@0: * An image client which uses two texture clients. michael@0: */ michael@0: class ImageClientBuffered : public ImageClientSingle michael@0: { michael@0: public: michael@0: ImageClientBuffered(CompositableForwarder* aFwd, michael@0: TextureFlags aFlags, michael@0: CompositableType aType); michael@0: michael@0: virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags); michael@0: michael@0: virtual void OnDetach() MOZ_OVERRIDE; michael@0: michael@0: virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE; michael@0: michael@0: protected: michael@0: RefPtr mBackBuffer; michael@0: }; michael@0: michael@0: /** michael@0: * Image class to be used for async image uploads using the image bridge michael@0: * protocol. michael@0: * We store the ImageBridge id in the TextureClientIdentifier. michael@0: */ michael@0: class ImageClientBridge : public ImageClient michael@0: { michael@0: public: michael@0: ImageClientBridge(CompositableForwarder* aFwd, michael@0: TextureFlags aFlags); michael@0: michael@0: virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags); michael@0: virtual bool Connect() { return false; } michael@0: virtual void Updated() {} michael@0: void SetLayer(ShadowableLayer* aLayer) michael@0: { michael@0: mLayer = aLayer; michael@0: } michael@0: michael@0: virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE michael@0: { michael@0: return TextureInfo(mType); michael@0: } michael@0: michael@0: virtual void SetIPDLActor(CompositableChild* aChild) MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(!aChild, "ImageClientBridge should not have IPDL actor"); michael@0: } michael@0: michael@0: virtual already_AddRefed CreateImage(ImageFormat aFormat) MOZ_OVERRIDE michael@0: { michael@0: NS_WARNING("Should not create an image through an ImageClientBridge"); michael@0: return nullptr; michael@0: } michael@0: michael@0: protected: michael@0: uint64_t mAsyncContainerID; michael@0: ShadowableLayer* mLayer; michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif