RenderTextureHostSWGL.h (2308B)
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_RENDERTEXTUREHOSTSWGL_H 8 #define MOZILLA_GFX_RENDERTEXTUREHOSTSWGL_H 9 10 #include "GLTypes.h" 11 #include "RenderTextureHost.h" 12 13 namespace mozilla { 14 namespace wr { 15 16 class RenderTextureHostSWGL : public RenderTextureHost { 17 public: 18 RenderTextureHostSWGL() {} 19 20 wr::WrExternalImage LockSWGL(uint8_t aChannelIndex, void* aContext, 21 RenderCompositor* aCompositor) override; 22 23 void UnlockSWGL() override; 24 25 RenderTextureHostSWGL* AsRenderTextureHostSWGL() override { return this; } 26 27 virtual size_t GetPlaneCount() const = 0; 28 29 virtual gfx::ColorDepth GetColorDepth() const { 30 return gfx::ColorDepth::COLOR_8; 31 } 32 33 struct PlaneInfo { 34 explicit PlaneInfo(GLuint aTexture) : mTexture(aTexture) {} 35 36 GLuint mTexture = 0; 37 void* mData = nullptr; 38 int32_t mStride = 0; 39 gfx::IntSize mSize; 40 }; 41 42 virtual bool MapPlane(RenderCompositor* aCompositor, uint8_t aChannelIndex, 43 PlaneInfo& aPlaneInfo) = 0; 44 45 virtual void UnmapPlanes() = 0; 46 47 // Lock this texture host as an attached external image for a SWGL compositor 48 // surface. See swgl_bindings.rs for a description of the resulting 49 // WrSWGLCompositeSurfaceInfo. This is paired with a call to UnlockSWGL when 50 // composition is done. 51 bool LockSWGLCompositeSurface(void* aContext, 52 wr::SWGLCompositeSurfaceInfo* aInfo); 53 54 size_t BytesFromPlanes() { 55 NS_ASSERTION(mPlanes.size(), "Can't compute bytes without any planes"); 56 size_t bytes = 0; 57 for (auto& plane : mPlanes) { 58 bytes += plane.mStride * plane.mSize.height; 59 } 60 return bytes; 61 } 62 63 protected: 64 bool mLocked = false; 65 void* mContext = nullptr; 66 std::vector<PlaneInfo> mPlanes; 67 68 bool SetContext(void* aContext); 69 70 bool UpdatePlanes(RenderCompositor* aCompositor); 71 72 void CleanupPlanes(); 73 74 virtual ~RenderTextureHostSWGL(); 75 }; 76 77 } // namespace wr 78 } // namespace mozilla 79 80 #endif // MOZILLA_GFX_RENDERTEXTUREHOSTSWGL_H