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.

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

mercurial