CanvasClient.h (2322B)
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_CANVASCLIENT_H 8 #define MOZILLA_GFX_CANVASCLIENT_H 9 10 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc 11 #include "mozilla/RefPtr.h" // for RefPtr, already_AddRefed 12 #include "mozilla/layers/CompositableClient.h" // for CompositableClient 13 #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc 14 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor 15 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc 16 #include "mozilla/layers/PersistentBufferProvider.h" 17 18 #include "mozilla/mozalloc.h" // for operator delete 19 20 #include "mozilla/gfx/Point.h" // for IntSize 21 #include "mozilla/gfx/Types.h" // for SurfaceFormat 22 23 namespace mozilla { 24 namespace layers { 25 26 class CompositableForwarder; 27 28 /** 29 * Compositable client for 2d and webgl canvas. 30 */ 31 class CanvasClient final : public CompositableClient { 32 int32_t mFrameID = 0; 33 RefPtr<TextureClient> mFrontBuffer; 34 35 public: 36 /** 37 * Creates, configures, and returns a new canvas client. If necessary, a 38 * message will be sent to the compositor to create a corresponding image 39 * host. 40 */ 41 CanvasClient(CompositableForwarder* aFwd, const TextureFlags flags) 42 : CompositableClient(aFwd, flags) {} 43 44 virtual ~CanvasClient() = default; 45 46 void Clear() { mFrontBuffer = nullptr; } 47 48 bool AddTextureClient(TextureClient* aTexture) override { 49 ++mFrameID; 50 return CompositableClient::AddTextureClient(aTexture); 51 } 52 53 TextureInfo GetTextureInfo() const override { 54 return TextureInfo(CompositableType::IMAGE, ImageUsageType::Canvas, 55 mTextureFlags); 56 } 57 58 void OnDetach() override { Clear(); } 59 60 RefPtr<TextureClient> CreateTextureClientForCanvas(gfx::SurfaceFormat, 61 gfx::IntSize, 62 TextureFlags); 63 void UseTexture(TextureClient*); 64 }; 65 66 } // namespace layers 67 } // namespace mozilla 68 69 #endif