gfx/layers/client/ImageClient.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/client/ImageClient.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,170 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef MOZILLA_GFX_IMAGECLIENT_H
    1.10 +#define MOZILLA_GFX_IMAGECLIENT_H
    1.11 +
    1.12 +#include <stdint.h>                     // for uint32_t, uint64_t
    1.13 +#include <sys/types.h>                  // for int32_t
    1.14 +#include "mozilla/Attributes.h"         // for MOZ_OVERRIDE
    1.15 +#include "mozilla/RefPtr.h"             // for RefPtr, TemporaryRef
    1.16 +#include "mozilla/gfx/Types.h"          // for SurfaceFormat
    1.17 +#include "mozilla/layers/CompositableClient.h"  // for CompositableClient
    1.18 +#include "mozilla/layers/CompositorTypes.h"  // for CompositableType, etc
    1.19 +#include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
    1.20 +#include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
    1.21 +#include "mozilla/mozalloc.h"           // for operator delete
    1.22 +#include "nsCOMPtr.h"                   // for already_AddRefed
    1.23 +#include "nsRect.h"                     // for nsIntRect
    1.24 +
    1.25 +namespace mozilla {
    1.26 +namespace layers {
    1.27 +
    1.28 +class CompositableForwarder;
    1.29 +class Image;
    1.30 +class ImageContainer;
    1.31 +class ShadowableLayer;
    1.32 +
    1.33 +/**
    1.34 + * Image clients are used by basic image layers on the content thread, they
    1.35 + * always match with an ImageHost on the compositor thread. See
    1.36 + * CompositableClient.h for information on connecting clients to hosts.
    1.37 + */
    1.38 +class ImageClient : public CompositableClient
    1.39 +{
    1.40 +public:
    1.41 +  /**
    1.42 +   * Creates, configures, and returns a new image client. If necessary, a
    1.43 +   * message will be sent to the compositor to create a corresponding image
    1.44 +   * host.
    1.45 +   */
    1.46 +  static TemporaryRef<ImageClient> CreateImageClient(CompositableType aImageHostType,
    1.47 +                                                     CompositableForwarder* aFwd,
    1.48 +                                                     TextureFlags aFlags);
    1.49 +
    1.50 +  virtual ~ImageClient() {}
    1.51 +
    1.52 +  /**
    1.53 +   * Update this ImageClient from aContainer in aLayer
    1.54 +   * returns false if this is the wrong kind of ImageClient for aContainer.
    1.55 +   * Note that returning true does not necessarily imply success
    1.56 +   */
    1.57 +  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags) = 0;
    1.58 +
    1.59 +  /**
    1.60 +   * The picture rect is the area of the texture which makes up the image. That
    1.61 +   * is, the area that should be composited. In texture space.
    1.62 +   */
    1.63 +  virtual void UpdatePictureRect(nsIntRect aPictureRect);
    1.64 +
    1.65 +  virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) = 0;
    1.66 +
    1.67 +  /**
    1.68 +   * Synchronously remove all the textures used by the image client.
    1.69 +   */
    1.70 +  virtual void FlushAllImages(bool aExceptFront) {}
    1.71 +
    1.72 +protected:
    1.73 +  ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
    1.74 +              CompositableType aType);
    1.75 +
    1.76 +  CompositableType mType;
    1.77 +  int32_t mLastPaintedImageSerial;
    1.78 +  nsIntRect mPictureRect;
    1.79 +};
    1.80 +
    1.81 +/**
    1.82 + * An image client which uses a single texture client.
    1.83 + */
    1.84 +class ImageClientSingle : public ImageClient
    1.85 +{
    1.86 +public:
    1.87 +  ImageClientSingle(CompositableForwarder* aFwd,
    1.88 +                    TextureFlags aFlags,
    1.89 +                    CompositableType aType);
    1.90 +
    1.91 +  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
    1.92 +
    1.93 +  virtual void OnDetach() MOZ_OVERRIDE;
    1.94 +
    1.95 +  virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE;
    1.96 +
    1.97 +  virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE;
    1.98 +
    1.99 +  virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE;
   1.100 +
   1.101 +  virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
   1.102 +
   1.103 +protected:
   1.104 +  virtual bool UpdateImageInternal(ImageContainer* aContainer, uint32_t aContentFlags, bool* aIsSwapped);
   1.105 +
   1.106 +protected:
   1.107 +  RefPtr<TextureClient> mFrontBuffer;
   1.108 +};
   1.109 +
   1.110 +/**
   1.111 + * An image client which uses two texture clients.
   1.112 + */
   1.113 +class ImageClientBuffered : public ImageClientSingle
   1.114 +{
   1.115 +public:
   1.116 +  ImageClientBuffered(CompositableForwarder* aFwd,
   1.117 +                      TextureFlags aFlags,
   1.118 +                      CompositableType aType);
   1.119 +
   1.120 +  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
   1.121 +
   1.122 +  virtual void OnDetach() MOZ_OVERRIDE;
   1.123 +
   1.124 +  virtual void FlushAllImages(bool aExceptFront) MOZ_OVERRIDE;
   1.125 +
   1.126 +protected:
   1.127 +  RefPtr<TextureClient> mBackBuffer;
   1.128 +};
   1.129 +
   1.130 +/**
   1.131 + * Image class to be used for async image uploads using the image bridge
   1.132 + * protocol.
   1.133 + * We store the ImageBridge id in the TextureClientIdentifier.
   1.134 + */
   1.135 +class ImageClientBridge : public ImageClient
   1.136 +{
   1.137 +public:
   1.138 +  ImageClientBridge(CompositableForwarder* aFwd,
   1.139 +                    TextureFlags aFlags);
   1.140 +
   1.141 +  virtual bool UpdateImage(ImageContainer* aContainer, uint32_t aContentFlags);
   1.142 +  virtual bool Connect() { return false; }
   1.143 +  virtual void Updated() {}
   1.144 +  void SetLayer(ShadowableLayer* aLayer)
   1.145 +  {
   1.146 +    mLayer = aLayer;
   1.147 +  }
   1.148 +
   1.149 +  virtual TextureInfo GetTextureInfo() const MOZ_OVERRIDE
   1.150 +  {
   1.151 +    return TextureInfo(mType);
   1.152 +  }
   1.153 +
   1.154 +  virtual void SetIPDLActor(CompositableChild* aChild) MOZ_OVERRIDE
   1.155 +  {
   1.156 +    MOZ_ASSERT(!aChild, "ImageClientBridge should not have IPDL actor");
   1.157 +  }
   1.158 +
   1.159 +  virtual already_AddRefed<Image> CreateImage(ImageFormat aFormat) MOZ_OVERRIDE
   1.160 +  {
   1.161 +    NS_WARNING("Should not create an image through an ImageClientBridge");
   1.162 +    return nullptr;
   1.163 +  }
   1.164 +
   1.165 +protected:
   1.166 +  uint64_t mAsyncContainerID;
   1.167 +  ShadowableLayer* mLayer;
   1.168 +};
   1.169 +
   1.170 +}
   1.171 +}
   1.172 +
   1.173 +#endif

mercurial