1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef MOZILLA_GFX_RENDERTEXTUREHOST_H
8 #define MOZILLA_GFX_RENDERTEXTUREHOST_H
12 #include "nsISupportsImpl.h"
13 #include "mozilla/Atomics.h"
14 #include "mozilla/gfx/2D.h"
15 #include "mozilla/layers/LayersSurfaces.h"
16 #include "mozilla/RefPtr.h"
17 #include "mozilla/webrender/webrender_ffi.h"
18 #include "mozilla/webrender/WebRenderTypes.h"
27 class TextureSourceProvider
;
32 class RenderEGLImageTextureHost
;
33 class RenderAndroidHardwareBufferTextureHost
;
34 class RenderAndroidSurfaceTextureHost
;
35 class RenderCompositor
;
36 class RenderDXGITextureHost
;
37 class RenderDXGIYCbCrTextureHost
;
38 class RenderDcompSurfaceTextureHost
;
39 class RenderMacIOSurfaceTextureHost
;
40 class RenderBufferTextureHost
;
41 class RenderTextureHostSWGL
;
42 class RenderTextureHostWrapper
;
44 void ActivateBindAndTexParameteri(gl::GLContext
* aGL
, GLenum aActiveTexture
,
45 GLenum aBindTarget
, GLuint aBindTexture
);
47 // RenderTextureHostUsageInfo holds information about how the RenderTextureHost
48 // is used. It is used by AsyncImagePipelineManager to determine how to render
50 class RenderTextureHostUsageInfo final
{
52 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHostUsageInfo
)
54 RenderTextureHostUsageInfo() : mCreationTimeStamp(TimeStamp::Now()) {}
56 bool VideoOverlayDisabled() { return mVideoOverlayDisabled
; }
57 void DisableVideoOverlay() { mVideoOverlayDisabled
= true; }
59 const TimeStamp mCreationTimeStamp
;
62 ~RenderTextureHostUsageInfo() = default;
64 // RenderTextureHost prefers to disable video overlay.
65 Atomic
<bool> mVideoOverlayDisabled
{false};
68 class RenderTextureHost
{
69 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHost
)
74 virtual gfx::SurfaceFormat
GetFormat() const {
75 return gfx::SurfaceFormat::UNKNOWN
;
78 virtual gfx::YUVRangedColorSpace
GetYUVColorSpace() const {
79 return gfx::YUVRangedColorSpace::Default
;
82 virtual wr::WrExternalImage
Lock(uint8_t aChannelIndex
, gl::GLContext
* aGL
);
84 virtual void Unlock() {}
86 virtual wr::WrExternalImage
LockSWGL(uint8_t aChannelIndex
, void* aContext
,
87 RenderCompositor
* aCompositor
);
89 virtual void UnlockSWGL() {}
91 virtual RefPtr
<layers::TextureSource
> CreateTextureSource(
92 layers::TextureSourceProvider
* aProvider
);
94 virtual void ClearCachedResources() {}
96 // Called asynchronouly when corresponding TextureHost's mCompositableCount
97 // becomes from 0 to 1. For now, it is used only for
98 // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
99 virtual void PrepareForUse() {}
100 // Called asynchronouly when corresponding TextureHost's is actually going to
101 // be used by WebRender. For now, it is used only for
102 // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
103 virtual void NotifyForUse() {}
104 // Called asynchronouly when corresponding TextureHost's mCompositableCount
105 // becomes 0. For now, it is used only for
106 // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
107 virtual void NotifyNotUsed() {}
108 // Returns true when RenderTextureHost needs SyncObjectHost::Synchronize()
109 // call, before its usage.
110 virtual bool SyncObjectNeeded() { return false; }
111 // Returns true when this texture was generated from a DRM-protected source.
112 bool IsFromDRMSource() { return mIsFromDRMSource
; }
113 void SetIsFromDRMSource(bool aIsFromDRMSource
) {
114 mIsFromDRMSource
= aIsFromDRMSource
;
117 virtual size_t Bytes() = 0;
119 virtual RenderDXGITextureHost
* AsRenderDXGITextureHost() { return nullptr; }
120 virtual RenderDXGIYCbCrTextureHost
* AsRenderDXGIYCbCrTextureHost() {
124 virtual RenderMacIOSurfaceTextureHost
* AsRenderMacIOSurfaceTextureHost() {
128 virtual RenderEGLImageTextureHost
* AsRenderEGLImageTextureHost() {
132 virtual RenderAndroidHardwareBufferTextureHost
*
133 AsRenderAndroidHardwareBufferTextureHost() {
137 virtual RenderAndroidSurfaceTextureHost
* AsRenderAndroidSurfaceTextureHost() {
141 virtual RenderTextureHostSWGL
* AsRenderTextureHostSWGL() { return nullptr; }
143 virtual RenderDcompSurfaceTextureHost
* AsRenderDcompSurfaceTextureHost() {
147 virtual void Destroy();
149 virtual void SetIsSoftwareDecodedVideo() {
150 MOZ_ASSERT_UNREACHABLE("unexpected to be called");
152 virtual bool IsSoftwareDecodedVideo() {
153 MOZ_ASSERT_UNREACHABLE("unexpected to be called");
157 // Get RenderTextureHostUsageInfo of the RenderTextureHost.
158 // If mRenderTextureHostUsageInfo and aUsageInfo are different, merge them to
159 // one RenderTextureHostUsageInfo.
160 virtual RefPtr
<RenderTextureHostUsageInfo
> GetOrMergeUsageInfo(
161 const MutexAutoLock
& aProofOfMapLock
,
162 RefPtr
<RenderTextureHostUsageInfo
> aUsageInfo
);
164 virtual RefPtr
<RenderTextureHostUsageInfo
> GetTextureHostUsageInfo(
165 const MutexAutoLock
& aProofOfMapLock
);
168 virtual ~RenderTextureHost();
170 bool mIsFromDRMSource
;
172 // protected by RenderThread::mRenderTextureMapLock
173 RefPtr
<RenderTextureHostUsageInfo
> mRenderTextureHostUsageInfo
;
175 friend class RenderTextureHostWrapper
;
179 } // namespace mozilla
181 #endif // MOZILLA_GFX_RENDERTEXTUREHOST_H