gfx/layers/client/CompositableClient.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/layers/client/CompositableClient.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     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_BUFFERCLIENT_H
    1.10 +#define MOZILLA_GFX_BUFFERCLIENT_H
    1.11 +
    1.12 +#include <stdint.h>                     // for uint64_t
    1.13 +#include <vector>                       // for vector
    1.14 +#include <map>                          // for map
    1.15 +#include "mozilla/Assertions.h"         // for MOZ_CRASH
    1.16 +#include "mozilla/RefPtr.h"             // for TemporaryRef, RefCounted
    1.17 +#include "mozilla/gfx/Types.h"          // for SurfaceFormat
    1.18 +#include "mozilla/layers/CompositorTypes.h"
    1.19 +#include "mozilla/layers/LayersTypes.h"  // for LayersBackend
    1.20 +#include "mozilla/layers/PCompositableChild.h"  // for PCompositableChild
    1.21 +#include "nsISupportsImpl.h"            // for MOZ_COUNT_CTOR, etc
    1.22 +
    1.23 +namespace mozilla {
    1.24 +namespace layers {
    1.25 +
    1.26 +class CompositableClient;
    1.27 +class TextureClient;
    1.28 +class BufferTextureClient;
    1.29 +class ImageBridgeChild;
    1.30 +class CompositableForwarder;
    1.31 +class CompositableChild;
    1.32 +class SurfaceDescriptor;
    1.33 +class TextureClientData;
    1.34 +
    1.35 +/**
    1.36 + * CompositableClient manages the texture-specific logic for composite layers,
    1.37 + * independently of the layer. It is the content side of a CompositableClient/
    1.38 + * CompositableHost pair.
    1.39 + *
    1.40 + * CompositableClient's purpose is to send texture data to the compositor side
    1.41 + * along with any extra information about how the texture is to be composited.
    1.42 + * Things like opacity or transformation belong to layer and not compositable.
    1.43 + *
    1.44 + * Since Compositables are independent of layers it is possible to create one,
    1.45 + * connect it to the compositor side, and start sending images to it. This alone
    1.46 + * is arguably not very useful, but it means that as long as a shadow layer can
    1.47 + * do the proper magic to find a reference to the right CompositableHost on the
    1.48 + * Compositor side, a Compositable client can be used outside of the main
    1.49 + * shadow layer forwarder machinery that is used on the main thread.
    1.50 + *
    1.51 + * The first step is to create a Compositable client and call Connect().
    1.52 + * Connect() creates the underlying IPDL actor (see CompositableChild) and the
    1.53 + * corresponding CompositableHost on the other side.
    1.54 + *
    1.55 + * To do in-transaction texture transfer (the default), call
    1.56 + * ShadowLayerForwarder::Attach(CompositableClient*, ShadowableLayer*). This
    1.57 + * will let the LayerComposite on the compositor side know which CompositableHost
    1.58 + * to use for compositing.
    1.59 + *
    1.60 + * To do async texture transfer (like async-video), the CompositableClient
    1.61 + * should be created with a different CompositableForwarder (like
    1.62 + * ImageBridgeChild) and attachment is done with
    1.63 + * CompositableForwarder::AttachAsyncCompositable that takes an identifier
    1.64 + * instead of a CompositableChild, since the CompositableClient is not managed
    1.65 + * by this layer forwarder (the matching uses a global map on the compositor side,
    1.66 + * see CompositableMap in ImageBridgeParent.cpp)
    1.67 + *
    1.68 + * Subclasses: Thebes layers use ContentClients, ImageLayers use ImageClients,
    1.69 + * Canvas layers use CanvasClients (but ImageHosts). We have a different subclass
    1.70 + * where we have a different way of interfacing with the textures - in terms of
    1.71 + * drawing into the compositable and/or passing its contents to the compostior.
    1.72 + */
    1.73 +class CompositableClient
    1.74 +{
    1.75 +protected:
    1.76 +  virtual ~CompositableClient();
    1.77 +
    1.78 +public:
    1.79 +  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CompositableClient)
    1.80 +
    1.81 +  CompositableClient(CompositableForwarder* aForwarder, TextureFlags aFlags = 0);
    1.82 +
    1.83 +  virtual TextureInfo GetTextureInfo() const = 0;
    1.84 +
    1.85 +  LayersBackend GetCompositorBackendType() const;
    1.86 +
    1.87 +  TemporaryRef<BufferTextureClient>
    1.88 +  CreateBufferTextureClient(gfx::SurfaceFormat aFormat,
    1.89 +                            TextureFlags aFlags = TEXTURE_FLAGS_DEFAULT,
    1.90 +                            gfx::BackendType aMoz2dBackend = gfx::BackendType::NONE);
    1.91 +
    1.92 +  TemporaryRef<TextureClient>
    1.93 +  CreateTextureClientForDrawing(gfx::SurfaceFormat aFormat,
    1.94 +                                TextureFlags aTextureFlags,
    1.95 +                                gfx::BackendType aMoz2dBackend,
    1.96 +                                const gfx::IntSize& aSizeHint);
    1.97 +
    1.98 +  virtual void SetDescriptorFromReply(TextureIdentifier aTextureId,
    1.99 +                                      const SurfaceDescriptor& aDescriptor)
   1.100 +  {
   1.101 +    MOZ_CRASH("If you want to call this, you should have implemented it");
   1.102 +  }
   1.103 +
   1.104 +  /**
   1.105 +   * Establishes the connection with compositor side through IPDL
   1.106 +   */
   1.107 +  virtual bool Connect();
   1.108 +
   1.109 +  void Destroy();
   1.110 +
   1.111 +  PCompositableChild* GetIPDLActor() const;
   1.112 +
   1.113 +  // should only be called by a CompositableForwarder
   1.114 +  virtual void SetIPDLActor(CompositableChild* aChild);
   1.115 +
   1.116 +  CompositableForwarder* GetForwarder() const
   1.117 +  {
   1.118 +    return mForwarder;
   1.119 +  }
   1.120 +
   1.121 +  /**
   1.122 +   * This identifier is what lets us attach async compositables with a shadow
   1.123 +   * layer. It is not used if the compositable is used with the regular shadow
   1.124 +   * layer forwarder.
   1.125 +   *
   1.126 +   * If this returns zero, it means the compositable is not async (it is used
   1.127 +   * on the main thread).
   1.128 +   */
   1.129 +  uint64_t GetAsyncID() const;
   1.130 +
   1.131 +  /**
   1.132 +   * Tells the Compositor to create a TextureHost for this TextureClient.
   1.133 +   */
   1.134 +  virtual bool AddTextureClient(TextureClient* aClient);
   1.135 +
   1.136 +  /**
   1.137 +   * A hook for the Compositable to execute whatever it held off for next transaction.
   1.138 +   */
   1.139 +  virtual void OnTransaction();
   1.140 +
   1.141 +  /**
   1.142 +   * A hook for the when the Compositable is detached from it's layer.
   1.143 +   */
   1.144 +  virtual void OnDetach() {}
   1.145 +
   1.146 +  /**
   1.147 +   * Clear any resources that are not immediately necessary. This may be called
   1.148 +   * in low-memory conditions.
   1.149 +   */
   1.150 +  virtual void ClearCachedResources() {}
   1.151 +
   1.152 +  static CompositableClient* FromIPDLActor(PCompositableChild* aActor);
   1.153 +
   1.154 +  /**
   1.155 +   * Allocate and deallocate a CompositableChild actor.
   1.156 +   *
   1.157 +   * CompositableChild is an implementation detail of CompositableClient that is not
   1.158 +   * exposed to the rest of the code base. CreateIPDLActor and DestroyIPDLActor
   1.159 +   * are for use with the managing IPDL protocols only (so that they can
   1.160 +   * implement AllocCompositableChild and DeallocPCompositableChild).
   1.161 +   */
   1.162 +  static PCompositableChild* CreateIPDLActor();
   1.163 +
   1.164 +  static bool DestroyIPDLActor(PCompositableChild* actor);
   1.165 +
   1.166 +  void InitIPDLActor(PCompositableChild* aActor, uint64_t aAsyncID = 0);
   1.167 +
   1.168 +protected:
   1.169 +  CompositableChild* mCompositableChild;
   1.170 +  CompositableForwarder* mForwarder;
   1.171 +  // Some layers may want to enforce some flags to all their textures
   1.172 +  // (like disallowing tiling)
   1.173 +  TextureFlags mTextureFlags;
   1.174 +
   1.175 +  friend class CompositableChild;
   1.176 +};
   1.177 +
   1.178 +} // namespace
   1.179 +} // namespace
   1.180 +
   1.181 +#endif

mercurial