Bug 1728955: part 6) Log result of Windows' `OleSetClipboardResult`. r=masayuki
[gecko.git] / gfx / gl / SharedSurface.h
blob39efab333f0fef7f639973aafcb128c8d5f7f2eb
1 /* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
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 /* SharedSurface abstracts an actual surface (can be a GL texture, but
7 * not necessarily) that handles sharing.
8 * Its specializations are:
9 * SharedSurface_Basic (client-side bitmap, does readback)
10 * SharedSurface_GLTexture
11 * SharedSurface_EGLImage
12 * SharedSurface_ANGLEShareHandle
15 #ifndef SHARED_SURFACE_H_
16 #define SHARED_SURFACE_H_
18 #include <queue>
19 #include <set>
20 #include <stdint.h>
22 #include "GLContext.h" // Bug 1635644
23 #include "GLContextTypes.h"
24 #include "GLDefs.h"
25 #include "mozilla/Attributes.h"
26 #include "mozilla/DebugOnly.h"
27 #include "mozilla/gfx/Point.h"
28 #include "mozilla/Mutex.h"
29 #include "mozilla/UniquePtr.h"
30 #include "mozilla/WeakPtr.h"
31 #include "SurfaceTypes.h"
33 class nsIThread;
35 namespace mozilla {
36 namespace gfx {
37 class DataSourceSurface;
38 class DrawTarget;
39 } // namespace gfx
41 namespace layers {
42 class KnowsCompositor;
43 enum class LayersBackend : int8_t;
44 class LayersIPCChannel;
45 class SharedSurfaceTextureClient;
46 class SurfaceDescriptor;
47 class TextureClient;
48 enum class TextureFlags : uint32_t;
49 enum class TextureType : int8_t;
50 } // namespace layers
52 namespace gl {
54 class MozFramebuffer;
55 struct ScopedBindFramebuffer;
56 class SurfaceFactory;
58 struct PartialSharedSurfaceDesc {
59 const WeakPtr<GLContext> gl;
60 const SharedSurfaceType type;
61 const layers::TextureType consumerType;
62 const bool canRecycle;
64 struct SharedSurfaceDesc : public PartialSharedSurfaceDesc {
65 gfx::IntSize size = {};
68 class SharedSurface {
69 public:
70 const SharedSurfaceDesc mDesc;
71 const UniquePtr<MozFramebuffer> mFb; // null if we should use fb=0.
73 protected:
74 bool mIsLocked = false;
75 bool mIsProducerAcquired = false;
77 SharedSurface(const SharedSurfaceDesc&, UniquePtr<MozFramebuffer>);
79 public:
80 virtual ~SharedSurface();
82 bool IsLocked() const { return mIsLocked; }
83 bool IsProducerAcquired() const { return mIsProducerAcquired; }
85 // This locks the SharedSurface as the production buffer for the context.
86 // This is needed by backends which use PBuffers and/or EGLSurfaces.
87 void LockProd();
89 // Unlocking is harmless if we're already unlocked.
90 void UnlockProd();
92 // This surface has been moved to the front buffer and will not be locked
93 // again until it is recycled. Do any finalization steps here.
94 virtual void Commit() {}
96 protected:
97 virtual void LockProdImpl(){};
98 virtual void UnlockProdImpl(){};
100 virtual void ProducerAcquireImpl(){};
101 virtual void ProducerReleaseImpl(){};
103 virtual void ProducerReadAcquireImpl() { ProducerAcquireImpl(); }
104 virtual void ProducerReadReleaseImpl() { ProducerReleaseImpl(); }
106 public:
107 void ProducerAcquire() {
108 MOZ_ASSERT(!mIsProducerAcquired);
109 ProducerAcquireImpl();
110 mIsProducerAcquired = true;
112 void ProducerRelease() {
113 MOZ_ASSERT(mIsProducerAcquired);
114 ProducerReleaseImpl();
115 mIsProducerAcquired = false;
117 void ProducerReadAcquire() {
118 MOZ_ASSERT(!mIsProducerAcquired);
119 ProducerReadAcquireImpl();
120 mIsProducerAcquired = true;
122 void ProducerReadRelease() {
123 MOZ_ASSERT(mIsProducerAcquired);
124 ProducerReadReleaseImpl();
125 mIsProducerAcquired = false;
128 // This function waits until the buffer is no longer being used.
129 // To optimize the performance, some implementaions recycle SharedSurfaces
130 // even when its buffer is still being used.
131 virtual void WaitForBufferOwnership() {}
133 // Returns true if the buffer is available.
134 // You can call WaitForBufferOwnership to wait for availability.
135 virtual bool IsBufferAvailable() const { return true; }
137 virtual bool NeedsIndirectReads() const { return false; }
139 virtual Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() = 0;
142 // -
144 class SurfaceFactory {
145 public:
146 const PartialSharedSurfaceDesc mDesc;
148 protected:
149 Mutex mMutex;
151 public:
152 static UniquePtr<SurfaceFactory> Create(GLContext*, layers::TextureType);
154 protected:
155 explicit SurfaceFactory(const PartialSharedSurfaceDesc&);
157 public:
158 virtual ~SurfaceFactory();
160 protected:
161 virtual UniquePtr<SharedSurface> CreateSharedImpl(
162 const SharedSurfaceDesc&) = 0;
164 public:
165 UniquePtr<SharedSurface> CreateShared(const gfx::IntSize& size) {
166 return CreateSharedImpl({mDesc, size});
170 template <typename T>
171 inline UniquePtr<T> AsUnique(T* const p) {
172 return UniquePtr<T>(p);
175 } // namespace gl
176 } // namespace mozilla
178 #endif // SHARED_SURFACE_H_