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

mercurial