gfx/layers/client/CompositableClient.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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_BUFFERCLIENT_H
     7 #define MOZILLA_GFX_BUFFERCLIENT_H
     9 #include <stdint.h>                     // for uint64_t
    10 #include <vector>                       // for vector
    11 #include <map>                          // for map
    12 #include "mozilla/Assertions.h"         // for MOZ_CRASH
    13 #include "mozilla/RefPtr.h"             // for TemporaryRef, RefCounted
    14 #include "mozilla/gfx/Types.h"          // for SurfaceFormat
    15 #include "mozilla/layers/CompositorTypes.h"
    16 #include "mozilla/layers/LayersTypes.h"  // for LayersBackend
    17 #include "mozilla/layers/PCompositableChild.h"  // for PCompositableChild
    18 #include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
    20 namespace mozilla {
    21 namespace layers {
    23 class CompositableClient;
    24 class TextureClient;
    25 class BufferTextureClient;
    26 class ImageBridgeChild;
    27 class CompositableForwarder;
    28 class CompositableChild;
    29 class SurfaceDescriptor;
    30 class TextureClientData;
    32 /**
    33  * CompositableClient manages the texture-specific logic for composite layers,
    34  * independently of the layer. It is the content side of a CompositableClient/
    35  * CompositableHost pair.
    36  *
    37  * CompositableClient's purpose is to send texture data to the compositor side
    38  * along with any extra information about how the texture is to be composited.
    39  * Things like opacity or transformation belong to layer and not compositable.
    40  *
    41  * Since Compositables are independent of layers it is possible to create one,
    42  * connect it to the compositor side, and start sending images to it. This alone
    43  * is arguably not very useful, but it means that as long as a shadow layer can
    44  * do the proper magic to find a reference to the right CompositableHost on the
    45  * Compositor side, a Compositable client can be used outside of the main
    46  * shadow layer forwarder machinery that is used on the main thread.
    47  *
    48  * The first step is to create a Compositable client and call Connect().
    49  * Connect() creates the underlying IPDL actor (see CompositableChild) and the
    50  * corresponding CompositableHost on the other side.
    51  *
    52  * To do in-transaction texture transfer (the default), call
    53  * ShadowLayerForwarder::Attach(CompositableClient*, ShadowableLayer*). This
    54  * will let the LayerComposite on the compositor side know which CompositableHost
    55  * to use for compositing.
    56  *
    57  * To do async texture transfer (like async-video), the CompositableClient
    58  * should be created with a different CompositableForwarder (like
    59  * ImageBridgeChild) and attachment is done with
    60  * CompositableForwarder::AttachAsyncCompositable that takes an identifier
    61  * instead of a CompositableChild, since the CompositableClient is not managed
    62  * by this layer forwarder (the matching uses a global map on the compositor side,
    63  * see CompositableMap in ImageBridgeParent.cpp)
    64  *
    65  * Subclasses: Thebes layers use ContentClients, ImageLayers use ImageClients,
    66  * Canvas layers use CanvasClients (but ImageHosts). We have a different subclass
    67  * where we have a different way of interfacing with the textures - in terms of
    68  * drawing into the compositable and/or passing its contents to the compostior.
    69  */
    70 class CompositableClient
    71 {
    72 protected:
    73   virtual ~CompositableClient();
    75 public:
    76   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableClient)
    78   CompositableClient(CompositableForwarder* aForwarder, TextureFlags aFlags = 0);
    80   virtual TextureInfo GetTextureInfo() const = 0;
    82   LayersBackend GetCompositorBackendType() const;
    84   TemporaryRef<BufferTextureClient>
    85   CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
    86                             TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT,
    87                             gfx::BackendType aMoz2dBackend = gfx::BackendType::NONE);
    89   TemporaryRef<TextureClient>
    90   CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat,
    91                                 TextureFlags aTextureFlags,
    92                                 gfx::BackendType aMoz2dBackend,
    93                                 const gfx::IntSize& aSizeHint);
    95   virtual void SetDescriptorFromReply(TextureIdentifier aTextureId,
    96                                       const SurfaceDescriptor& aDescriptor)
    97   {
    98     MOZ_CRASH("If you want to call this, you should have implemented it");
    99   }
   101   /**
   102    * Establishes the connection with compositor side through IPDL
   103    */
   104   virtual bool Connect();
   106   void Destroy();
   108   PCompositableChild* GetIPDLActor() const;
   110   // should only be called by a CompositableForwarder
   111   virtual void SetIPDLActor(CompositableChild* aChild);
   113   CompositableForwarder* GetForwarder() const
   114   {
   115     return mForwarder;
   116   }
   118   /**
   119    * This identifier is what lets us attach async compositables with a shadow
   120    * layer. It is not used if the compositable is used with the regular shadow
   121    * layer forwarder.
   122    *
   123    * If this returns zero, it means the compositable is not async (it is used
   124    * on the main thread).
   125    */
   126   uint64_t GetAsyncID() const;
   128   /**
   129    * Tells the Compositor to create a TextureHost for this TextureClient.
   130    */
   131   virtual bool AddTextureClient(TextureClient* aClient);
   133   /**
   134    * A hook for the Compositable to execute whatever it held off for next transaction.
   135    */
   136   virtual void OnTransaction();
   138   /**
   139    * A hook for the when the Compositable is detached from it's layer.
   140    */
   141   virtual void OnDetach() {}
   143   /**
   144    * Clear any resources that are not immediately necessary. This may be called
   145    * in low-memory conditions.
   146    */
   147   virtual void ClearCachedResources() {}
   149   static CompositableClient* FromIPDLActor(PCompositableChild* aActor);
   151   /**
   152    * Allocate and deallocate a CompositableChild actor.
   153    *
   154    * CompositableChild is an implementation detail of CompositableClient that is not
   155    * exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
   156    * are for use with the managing IPDL protocols only (so that they can
   157    * implement AllocCompositableChild and DeallocPCompositableChild).
   158    */
   159   static PCompositableChild* CreateIPDLActor();
   161   static bool DestroyIPDLActor(PCompositableChild* actor);
   163   void InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID = 0);
   165 protected:
   166   CompositableChild* mCompositableChild;
   167   CompositableForwarder* mForwarder;
   168   // Some layers may want to enforce some flags to all their textures
   169   // (like disallowing tiling)
   170   TextureFlags mTextureFlags;
   172   friend class CompositableChild;
   173 };
   175 } // namespace
   176 } // namespace
   178 #endif

mercurial