gfx/layers/client/CanvasClient.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZILLA_GFX_CANVASCLIENT_H
michael@0 7 #define MOZILLA_GFX_CANVASCLIENT_H
michael@0 8
michael@0 9 #include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
michael@0 10 #include "mozilla/Attributes.h" // for MOZ_OVERRIDE
michael@0 11 #include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef
michael@0 12 #include "mozilla/layers/CompositableClient.h" // for CompositableClient
michael@0 13 #include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc
michael@0 14 #include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor
michael@0 15 #include "mozilla/layers/TextureClient.h" // for TextureClient, etc
michael@0 16 #include "mozilla/mozalloc.h" // for operator delete
michael@0 17
michael@0 18 #include "mozilla/gfx/Point.h" // for IntSize
michael@0 19 #include "mozilla/gfx/Types.h" // for SurfaceFormat
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22 namespace gfx {
michael@0 23 class SharedSurface;
michael@0 24 }
michael@0 25 }
michael@0 26
michael@0 27 namespace mozilla {
michael@0 28 namespace layers {
michael@0 29
michael@0 30 class ClientCanvasLayer;
michael@0 31 class CompositableForwarder;
michael@0 32
michael@0 33 /**
michael@0 34 * Compositable client for 2d and webgl canvas.
michael@0 35 */
michael@0 36 class CanvasClient : public CompositableClient
michael@0 37 {
michael@0 38 public:
michael@0 39 /**
michael@0 40 * Creates, configures, and returns a new canvas client. If necessary, a
michael@0 41 * message will be sent to the compositor to create a corresponding image
michael@0 42 * host.
michael@0 43 */
michael@0 44 enum CanvasClientType {
michael@0 45 CanvasClientSurface,
michael@0 46 CanvasClientGLContext,
michael@0 47 };
michael@0 48 static TemporaryRef<CanvasClient> CreateCanvasClient(CanvasClientType aType,
michael@0 49 CompositableForwarder* aFwd,
michael@0 50 TextureFlags aFlags);
michael@0 51
michael@0 52 CanvasClient(CompositableForwarder* aFwd, TextureFlags aFlags)
michael@0 53 : CompositableClient(aFwd, aFlags)
michael@0 54 {
michael@0 55 mTextureInfo.mTextureFlags = aFlags;
michael@0 56 }
michael@0 57
michael@0 58 virtual ~CanvasClient() {}
michael@0 59
michael@0 60 virtual void Clear() {};
michael@0 61
michael@0 62 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) = 0;
michael@0 63
michael@0 64 virtual void Updated() { }
michael@0 65
michael@0 66 protected:
michael@0 67 TextureInfo mTextureInfo;
michael@0 68 };
michael@0 69
michael@0 70 // Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried.
michael@0 71 class CanvasClient2D : public CanvasClient
michael@0 72 {
michael@0 73 public:
michael@0 74 CanvasClient2D(CompositableForwarder* aLayerForwarder,
michael@0 75 TextureFlags aFlags)
michael@0 76 : CanvasClient(aLayerForwarder, aFlags)
michael@0 77 {
michael@0 78 }
michael@0 79
michael@0 80 TextureInfo GetTextureInfo() const
michael@0 81 {
michael@0 82 return TextureInfo(COMPOSITABLE_IMAGE);
michael@0 83 }
michael@0 84
michael@0 85 virtual void Clear() MOZ_OVERRIDE
michael@0 86 {
michael@0 87 mBuffer = nullptr;
michael@0 88 }
michael@0 89
michael@0 90 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
michael@0 91
michael@0 92 virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE
michael@0 93 {
michael@0 94 MOZ_ASSERT((mTextureInfo.mTextureFlags & aTexture->GetFlags()) == mTextureInfo.mTextureFlags);
michael@0 95 return CompositableClient::AddTextureClient(aTexture);
michael@0 96 }
michael@0 97
michael@0 98 virtual void OnDetach() MOZ_OVERRIDE
michael@0 99 {
michael@0 100 mBuffer = nullptr;
michael@0 101 }
michael@0 102
michael@0 103 private:
michael@0 104 RefPtr<TextureClient> mBuffer;
michael@0 105 };
michael@0 106
michael@0 107 // Used for GL canvases where we don't need to do any readback, i.e., with a
michael@0 108 // GL backend.
michael@0 109 class CanvasClientSurfaceStream : public CanvasClient
michael@0 110 {
michael@0 111 public:
michael@0 112 CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, TextureFlags aFlags);
michael@0 113
michael@0 114 TextureInfo GetTextureInfo() const
michael@0 115 {
michael@0 116 return TextureInfo(COMPOSITABLE_IMAGE);
michael@0 117 }
michael@0 118
michael@0 119 virtual void Clear() MOZ_OVERRIDE
michael@0 120 {
michael@0 121 mBuffer = nullptr;
michael@0 122 }
michael@0 123
michael@0 124 virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE;
michael@0 125
michael@0 126 virtual void OnDetach() MOZ_OVERRIDE
michael@0 127 {
michael@0 128 mBuffer = nullptr;
michael@0 129 }
michael@0 130
michael@0 131 private:
michael@0 132 RefPtr<TextureClient> mBuffer;
michael@0 133 };
michael@0 134
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 #endif

mercurial