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 #include "RenderSharedSurfaceTextureHost.h"
9 #include "mozilla/gfx/Logging.h"
10 #include "mozilla/layers/ImageDataSerializer.h"
11 #include "mozilla/layers/SourceSurfaceSharedData.h"
16 RenderSharedSurfaceTextureHost::RenderSharedSurfaceTextureHost(
17 gfx::SourceSurfaceSharedDataWrapper
* aSurface
)
18 : mSurface(aSurface
), mMap(), mLocked(false) {
19 MOZ_COUNT_CTOR_INHERITED(RenderSharedSurfaceTextureHost
, RenderTextureHost
);
23 RenderSharedSurfaceTextureHost::~RenderSharedSurfaceTextureHost() {
24 MOZ_COUNT_DTOR_INHERITED(RenderSharedSurfaceTextureHost
, RenderTextureHost
);
27 wr::WrExternalImage
RenderSharedSurfaceTextureHost::Lock(
28 uint8_t aChannelIndex
, gl::GLContext
* aGL
, wr::ImageRendering aRendering
) {
30 if (NS_WARN_IF(!mSurface
->Map(gfx::DataSourceSurface::MapType::READ_WRITE
,
32 return InvalidToWrExternalImage();
37 return RawDataToWrExternalImage(mMap
.mData
,
38 mMap
.mStride
* mSurface
->GetSize().height
);
41 void RenderSharedSurfaceTextureHost::Unlock() {
48 size_t RenderSharedSurfaceTextureHost::Bytes() {
49 return mSurface
->Stride() * mSurface
->GetSize().height
;
52 size_t RenderSharedSurfaceTextureHost::GetPlaneCount() const { return 1; }
54 gfx::SurfaceFormat
RenderSharedSurfaceTextureHost::GetFormat() const {
55 return mSurface
->GetFormat();
58 gfx::ColorDepth
RenderSharedSurfaceTextureHost::GetColorDepth() const {
59 return gfx::ColorDepth::COLOR_8
;
62 bool RenderSharedSurfaceTextureHost::MapPlane(RenderCompositor
* aCompositor
,
63 uint8_t aChannelIndex
,
64 PlaneInfo
& aPlaneInfo
) {
66 !mSurface
->Map(gfx::DataSourceSurface::MapType::READ
, &mMap
))) {
69 aPlaneInfo
.mData
= mMap
.mData
;
70 aPlaneInfo
.mStride
= mMap
.mStride
;
71 aPlaneInfo
.mSize
= mSurface
->GetSize();
75 void RenderSharedSurfaceTextureHost::UnmapPlanes() { mSurface
->Unmap(); }
78 } // namespace mozilla