1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/client/CanvasClient.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,138 @@ 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_CANVASCLIENT_H 1.10 +#define MOZILLA_GFX_CANVASCLIENT_H 1.11 + 1.12 +#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc 1.13 +#include "mozilla/Attributes.h" // for MOZ_OVERRIDE 1.14 +#include "mozilla/RefPtr.h" // for RefPtr, TemporaryRef 1.15 +#include "mozilla/layers/CompositableClient.h" // for CompositableClient 1.16 +#include "mozilla/layers/CompositorTypes.h" // for TextureInfo, etc 1.17 +#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor 1.18 +#include "mozilla/layers/TextureClient.h" // for TextureClient, etc 1.19 +#include "mozilla/mozalloc.h" // for operator delete 1.20 + 1.21 +#include "mozilla/gfx/Point.h" // for IntSize 1.22 +#include "mozilla/gfx/Types.h" // for SurfaceFormat 1.23 + 1.24 +namespace mozilla { 1.25 +namespace gfx { 1.26 +class SharedSurface; 1.27 +} 1.28 +} 1.29 + 1.30 +namespace mozilla { 1.31 +namespace layers { 1.32 + 1.33 +class ClientCanvasLayer; 1.34 +class CompositableForwarder; 1.35 + 1.36 +/** 1.37 + * Compositable client for 2d and webgl canvas. 1.38 + */ 1.39 +class CanvasClient : public CompositableClient 1.40 +{ 1.41 +public: 1.42 + /** 1.43 + * Creates, configures, and returns a new canvas client. If necessary, a 1.44 + * message will be sent to the compositor to create a corresponding image 1.45 + * host. 1.46 + */ 1.47 + enum CanvasClientType { 1.48 + CanvasClientSurface, 1.49 + CanvasClientGLContext, 1.50 + }; 1.51 + static TemporaryRef<CanvasClient> CreateCanvasClient(CanvasClientType aType, 1.52 + CompositableForwarder* aFwd, 1.53 + TextureFlags aFlags); 1.54 + 1.55 + CanvasClient(CompositableForwarder* aFwd, TextureFlags aFlags) 1.56 + : CompositableClient(aFwd, aFlags) 1.57 + { 1.58 + mTextureInfo.mTextureFlags = aFlags; 1.59 + } 1.60 + 1.61 + virtual ~CanvasClient() {} 1.62 + 1.63 + virtual void Clear() {}; 1.64 + 1.65 + virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) = 0; 1.66 + 1.67 + virtual void Updated() { } 1.68 + 1.69 +protected: 1.70 + TextureInfo mTextureInfo; 1.71 +}; 1.72 + 1.73 +// Used for 2D canvases and WebGL canvas on non-GL systems where readback is requried. 1.74 +class CanvasClient2D : public CanvasClient 1.75 +{ 1.76 +public: 1.77 + CanvasClient2D(CompositableForwarder* aLayerForwarder, 1.78 + TextureFlags aFlags) 1.79 + : CanvasClient(aLayerForwarder, aFlags) 1.80 + { 1.81 + } 1.82 + 1.83 + TextureInfo GetTextureInfo() const 1.84 + { 1.85 + return TextureInfo(COMPOSITABLE_IMAGE); 1.86 + } 1.87 + 1.88 + virtual void Clear() MOZ_OVERRIDE 1.89 + { 1.90 + mBuffer = nullptr; 1.91 + } 1.92 + 1.93 + virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE; 1.94 + 1.95 + virtual bool AddTextureClient(TextureClient* aTexture) MOZ_OVERRIDE 1.96 + { 1.97 + MOZ_ASSERT((mTextureInfo.mTextureFlags & aTexture->GetFlags()) == mTextureInfo.mTextureFlags); 1.98 + return CompositableClient::AddTextureClient(aTexture); 1.99 + } 1.100 + 1.101 + virtual void OnDetach() MOZ_OVERRIDE 1.102 + { 1.103 + mBuffer = nullptr; 1.104 + } 1.105 + 1.106 +private: 1.107 + RefPtr<TextureClient> mBuffer; 1.108 +}; 1.109 + 1.110 +// Used for GL canvases where we don't need to do any readback, i.e., with a 1.111 +// GL backend. 1.112 +class CanvasClientSurfaceStream : public CanvasClient 1.113 +{ 1.114 +public: 1.115 + CanvasClientSurfaceStream(CompositableForwarder* aLayerForwarder, TextureFlags aFlags); 1.116 + 1.117 + TextureInfo GetTextureInfo() const 1.118 + { 1.119 + return TextureInfo(COMPOSITABLE_IMAGE); 1.120 + } 1.121 + 1.122 + virtual void Clear() MOZ_OVERRIDE 1.123 + { 1.124 + mBuffer = nullptr; 1.125 + } 1.126 + 1.127 + virtual void Update(gfx::IntSize aSize, ClientCanvasLayer* aLayer) MOZ_OVERRIDE; 1.128 + 1.129 + virtual void OnDetach() MOZ_OVERRIDE 1.130 + { 1.131 + mBuffer = nullptr; 1.132 + } 1.133 + 1.134 +private: 1.135 + RefPtr<TextureClient> mBuffer; 1.136 +}; 1.137 + 1.138 +} 1.139 +} 1.140 + 1.141 +#endif