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_RENDEREXTERNALTEXTUREHOST_H
8 #define MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H
10 #include "mozilla/layers/TextureHostOGL.h"
11 #include "RenderTextureHostSWGL.h"
17 * RenderExternalTextureHost manages external textures used by WebRender on Mac.
18 * The motivation for this is to be able to use Apple Client Storage OpenGL
19 * extension, which makes it possible to avoid some copies during texture
20 * upload. This is especially helpful for high resolution video.
22 class RenderExternalTextureHost final
: public RenderTextureHostSWGL
{
24 RenderExternalTextureHost(uint8_t* aBuffer
,
25 const layers::BufferDescriptor
& aDescriptor
);
27 wr::WrExternalImage
Lock(uint8_t aChannelIndex
, gl::GLContext
* aGL
) override
;
28 void Unlock() override
;
29 void PrepareForUse() override
;
30 size_t Bytes() override
{
31 return mSize
.width
* mSize
.height
* BytesPerPixel(mFormat
);
34 // RenderTextureHostSWGL
35 size_t GetPlaneCount() const override
;
37 gfx::SurfaceFormat
GetFormat() const override
;
39 gfx::ColorDepth
GetColorDepth() const override
;
41 gfx::YUVRangedColorSpace
GetYUVColorSpace() const override
;
43 bool MapPlane(RenderCompositor
* aCompositor
, uint8_t aChannelIndex
,
44 PlaneInfo
& aPlaneInfo
) override
;
46 void UnmapPlanes() override
;
49 ~RenderExternalTextureHost();
51 bool CreateSurfaces();
52 void DeleteSurfaces();
53 void DeleteTextures();
55 uint8_t* GetBuffer() const { return mBuffer
; }
56 bool InitializeIfNeeded();
57 bool IsReadyForDeletion();
58 bool IsYUV() const { return mFormat
== gfx::SurfaceFormat::YUV420
; }
59 size_t PlaneCount() const { return IsYUV() ? 3 : 1; }
60 void UpdateTexture(size_t aIndex
);
61 void UpdateTextures();
64 layers::BufferDescriptor mDescriptor
;
67 bool mTextureUpdateNeeded
;
70 gfx::SurfaceFormat mFormat
;
72 RefPtr
<gl::GLContext
> mGL
;
73 RefPtr
<gfx::DataSourceSurface
> mSurfaces
[3];
74 RefPtr
<layers::DirectMapTextureSource
> mTextureSources
[3];
75 wr::WrExternalImage mImages
[3];
79 } // namespace mozilla
81 #endif // MOZILLA_GFX_RENDEREXTERNALTEXTUREHOST_H