tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ImageClient.h (3951B)


      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_IMAGECLIENT_H
      8 #define MOZILLA_GFX_IMAGECLIENT_H
      9 
     10 #include <stdint.h>                             // for uint32_t, uint64_t
     11 #include <sys/types.h>                          // for int32_t
     12 #include "mozilla/RefPtr.h"                     // for RefPtr, already_AddRefed
     13 #include "mozilla/gfx/Types.h"                  // for SurfaceFormat
     14 #include "mozilla/layers/CompositableClient.h"  // for CompositableClient
     15 #include "mozilla/layers/CompositorTypes.h"     // for CompositableType, etc
     16 #include "mozilla/layers/LayersSurfaces.h"      // for SurfaceDescriptor
     17 #include "mozilla/layers/TextureClient.h"       // for TextureClient, etc
     18 #include "mozilla/mozalloc.h"                   // for operator delete
     19 #include "nsCOMPtr.h"                           // for already_AddRefed
     20 #include "nsRect.h"                             // for mozilla::gfx::IntRect
     21 
     22 namespace mozilla {
     23 namespace layers {
     24 
     25 class CompositableForwarder;
     26 class Image;
     27 class ImageContainer;
     28 class ImageClientSingle;
     29 
     30 /**
     31 * Image clients are used by basic image layers on the content thread, they
     32 * always match with an ImageHost on the compositor thread. See
     33 * CompositableClient.h for information on connecting clients to hosts.
     34 */
     35 class ImageClient : public CompositableClient {
     36 public:
     37  /**
     38   * Creates, configures, and returns a new image client. If necessary, a
     39   * message will be sent to the compositor to create a corresponding image
     40   * host.
     41   */
     42  static already_AddRefed<ImageClient> CreateImageClient(
     43      CompositableType aImageHostType, ImageUsageType aUsageType,
     44      CompositableForwarder* aFwd, TextureFlags aFlags);
     45 
     46  virtual ~ImageClient() = default;
     47 
     48  /**
     49   * Update this ImageClient from aContainer in aLayer
     50   * returns false if this is the wrong kind of ImageClient for aContainer.
     51   * Note that returning true does not necessarily imply success
     52   */
     53  virtual bool UpdateImage(ImageContainer* aContainer) = 0;
     54 
     55  /**
     56   * asynchronously clear Images(textures) in host.
     57   *
     58   */
     59  virtual void ClearImagesInHost(ClearImagesType aType) {}
     60 
     61  virtual void RemoveTexture(TextureClient* aTexture) override;
     62 
     63  virtual ImageClientSingle* AsImageClientSingle() { return nullptr; }
     64 
     65  static already_AddRefed<TextureClient> CreateTextureClientForImage(
     66      Image* aImage, KnowsCompositor* aForwarder);
     67 
     68  uint32_t GetLastUpdateGenerationCounter() {
     69    return mLastUpdateGenerationCounter;
     70  }
     71 
     72  virtual RefPtr<TextureClient> GetForwardedTexture() { return nullptr; }
     73 
     74  CompositableType mType;
     75  ImageUsageType mUsageType;
     76 
     77 protected:
     78  ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
     79              CompositableType aType, ImageUsageType aUsageType);
     80 
     81  uint32_t mLastUpdateGenerationCounter;
     82 };
     83 
     84 /**
     85 * An image client which uses a single texture client.
     86 */
     87 class ImageClientSingle : public ImageClient {
     88 public:
     89  ImageClientSingle(CompositableForwarder* aFwd, TextureFlags aFlags,
     90                    CompositableType aType, ImageUsageType aUsageType);
     91 
     92  bool UpdateImage(ImageContainer* aContainer) override;
     93 
     94  void OnDetach() override;
     95 
     96  bool AddTextureClient(TextureClient* aTexture) override;
     97 
     98  TextureInfo GetTextureInfo() const override;
     99 
    100  void ClearImagesInHost(ClearImagesType aType) override;
    101 
    102  ImageClientSingle* AsImageClientSingle() override { return this; }
    103 
    104  RefPtr<TextureClient> GetForwardedTexture() override;
    105 
    106  bool IsEmpty() { return mBuffers.IsEmpty(); }
    107 
    108 protected:
    109  struct Buffer {
    110    RefPtr<TextureClient> mTextureClient;
    111    int32_t mImageSerial;
    112  };
    113  nsTArray<Buffer> mBuffers;
    114 };
    115 
    116 }  // namespace layers
    117 }  // namespace mozilla
    118 
    119 #endif