Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / gfx / layers / client / ImageClient.h
blob899e40adffad3f7f3ec6050dbb1280c4e97d93fc
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/. */
7 #ifndef MOZILLA_GFX_IMAGECLIENT_H
8 #define MOZILLA_GFX_IMAGECLIENT_H
10 #include <stdint.h> // for uint32_t, uint64_t
11 #include <sys/types.h> // for int32_t
12 #include "mozilla/Attributes.h" // for override
13 #include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed
14 #include "mozilla/gfx/Types.h" // for SurfaceFormat
15 #include "mozilla/layers/CompositableClient.h" // for CompositableClient
16 #include "mozilla/layers/CompositorTypes.h" // for CompositableType, etc
17 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
18 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc
19 #include "mozilla/mozalloc.h" // for operator delete
20 #include "nsCOMPtr.h" // for already_AddRefed
21 #include "nsRect.h" // for mozilla::gfx::IntRect
23 namespace mozilla {
24 namespace layers {
26 class CompositableForwarder;
27 class Image;
28 class ImageContainer;
29 class ImageClientSingle;
31 /**
32 * Image clients are used by basic image layers on the content thread, they
33 * always match with an ImageHost on the compositor thread. See
34 * CompositableClient.h for information on connecting clients to hosts.
36 class ImageClient : public CompositableClient {
37 public:
38 /**
39 * Creates, configures, and returns a new image client. If necessary, a
40 * message will be sent to the compositor to create a corresponding image
41 * host.
43 static already_AddRefed<ImageClient> CreateImageClient(
44 CompositableType aImageHostType, CompositableForwarder* aFwd,
45 TextureFlags aFlags);
47 virtual ~ImageClient() = default;
49 /**
50 * Update this ImageClient from aContainer in aLayer
51 * returns false if this is the wrong kind of ImageClient for aContainer.
52 * Note that returning true does not necessarily imply success
54 virtual bool UpdateImage(ImageContainer* aContainer) = 0;
56 /**
57 * asynchronously remove all the textures used by the image client.
60 virtual void FlushAllImages() {}
62 virtual void RemoveTexture(TextureClient* aTexture) override;
64 virtual ImageClientSingle* AsImageClientSingle() { return nullptr; }
66 static already_AddRefed<TextureClient> CreateTextureClientForImage(
67 Image* aImage, KnowsCompositor* aForwarder);
69 uint32_t GetLastUpdateGenerationCounter() {
70 return mLastUpdateGenerationCounter;
73 virtual RefPtr<TextureClient> GetForwardedTexture() { return nullptr; }
75 protected:
76 ImageClient(CompositableForwarder* aFwd, TextureFlags aFlags,
77 CompositableType aType);
79 CompositableType mType;
80 uint32_t mLastUpdateGenerationCounter;
83 /**
84 * An image client which uses a single texture client.
86 class ImageClientSingle : public ImageClient {
87 public:
88 ImageClientSingle(CompositableForwarder* aFwd, TextureFlags aFlags,
89 CompositableType aType);
91 bool UpdateImage(ImageContainer* aContainer) override;
93 void OnDetach() override;
95 bool AddTextureClient(TextureClient* aTexture) override;
97 TextureInfo GetTextureInfo() const override;
99 void FlushAllImages() override;
101 ImageClientSingle* AsImageClientSingle() override { return this; }
103 RefPtr<TextureClient> GetForwardedTexture() override;
105 bool IsEmpty() { return mBuffers.IsEmpty(); }
107 protected:
108 struct Buffer {
109 RefPtr<TextureClient> mTextureClient;
110 int32_t mImageSerial;
112 nsTArray<Buffer> mBuffers;
115 } // namespace layers
116 } // namespace mozilla
118 #endif