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/. */
6 
7 #ifndef MOZILLA_GFX_RENDERTEXTUREHOST_H
8 #define MOZILLA_GFX_RENDERTEXTUREHOST_H
9 
10 #include "GLConsts.h"
11 #include "GLTypes.h"
12 #include "nsISupportsImpl.h"
13 #include "mozilla/gfx/2D.h"
14 #include "mozilla/layers/LayersSurfaces.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/webrender/webrender_ffi.h"  // for wr::ImageRendering
17 #include "mozilla/webrender/WebRenderTypes.h"
18 
19 namespace mozilla {
20 
21 namespace gl {
22 class GLContext;
23 }
24 
25 namespace wr {
26 
27 class RenderAndroidSurfaceTextureHost;
28 class RenderCompositor;
29 class RenderDXGITextureHost;
30 class RenderDXGIYCbCrTextureHost;
31 class RenderMacIOSurfaceTextureHost;
32 class RenderBufferTextureHost;
33 class RenderTextureHostSWGL;
34 
35 void ActivateBindAndTexParameteri(gl::GLContext* aGL, GLenum aActiveTexture,
36                                   GLenum aBindTarget, GLuint aBindTexture,
37                                   wr::ImageRendering aRendering);
38 
39 class RenderTextureHost {
40   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHost)
41 
42  public:
43   RenderTextureHost();
44 
45   virtual wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL,
46                                    wr::ImageRendering aRendering);
47 
Unlock()48   virtual void Unlock() {}
49 
50   virtual wr::WrExternalImage LockSWGL(uint8_t aChannelIndex, void* aContext,
51                                        RenderCompositor* aCompositor,
52                                        wr::ImageRendering aRendering);
53 
UnlockSWGL()54   virtual void UnlockSWGL() {}
55 
ClearCachedResources()56   virtual void ClearCachedResources() {}
57 
58   // Called asynchronouly when corresponding TextureHost's mCompositableCount
59   // becomes from 0 to 1. For now, it is used only for
60   // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
PrepareForUse()61   virtual void PrepareForUse() {}
62   // Called asynchronouly when corresponding TextureHost's is actually going to
63   // be used by WebRender. For now, it is used only for
64   // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
NotifyForUse()65   virtual void NotifyForUse() {}
66   // Called asynchronouly when corresponding TextureHost's mCompositableCount
67   // becomes 0. For now, it is used only for
68   // SurfaceTextureHost/RenderAndroidSurfaceTextureHost.
NotifyNotUsed()69   virtual void NotifyNotUsed() {}
70   // Returns true when RenderTextureHost needs SyncObjectHost::Synchronize()
71   // call, before its usage.
SyncObjectNeeded()72   virtual bool SyncObjectNeeded() { return false; }
73 
74   virtual size_t Bytes() = 0;
75 
AsRenderDXGITextureHost()76   virtual RenderDXGITextureHost* AsRenderDXGITextureHost() { return nullptr; }
AsRenderDXGIYCbCrTextureHost()77   virtual RenderDXGIYCbCrTextureHost* AsRenderDXGIYCbCrTextureHost() {
78     return nullptr;
79   }
80 
AsRenderMacIOSurfaceTextureHost()81   virtual RenderMacIOSurfaceTextureHost* AsRenderMacIOSurfaceTextureHost() {
82     return nullptr;
83   }
84 
AsRenderAndroidSurfaceTextureHost()85   virtual RenderAndroidSurfaceTextureHost* AsRenderAndroidSurfaceTextureHost() {
86     return nullptr;
87   }
88 
AsRenderTextureHostSWGL()89   virtual RenderTextureHostSWGL* AsRenderTextureHostSWGL() { return nullptr; }
90 
91  protected:
92   virtual ~RenderTextureHost();
93 
94   bool IsFilterUpdateNecessary(wr::ImageRendering aRendering);
95 
96   wr::ImageRendering mCachedRendering;
97 };
98 
99 }  // namespace wr
100 }  // namespace mozilla
101 
102 #endif  // MOZILLA_GFX_RENDERTEXTUREHOST_H
103