Bug 1732219 - Add API for fetching the preview image. r=geckoview-reviewers,agi,mconley
[gecko.git] / gfx / webrender_bindings / RenderSharedSurfaceTextureHost.cpp
blobfbc2baaf1ba1ff9d082c636ccfe483b3d69be80d
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"
13 namespace mozilla {
14 namespace wr {
16 RenderSharedSurfaceTextureHost::RenderSharedSurfaceTextureHost(
17 gfx::SourceSurfaceSharedDataWrapper* aSurface)
18 : mSurface(aSurface), mMap(), mLocked(false) {
19 MOZ_COUNT_CTOR_INHERITED(RenderSharedSurfaceTextureHost, RenderTextureHost);
20 MOZ_ASSERT(aSurface);
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) {
29 if (!mLocked) {
30 if (NS_WARN_IF(!mSurface->Map(gfx::DataSourceSurface::MapType::READ_WRITE,
31 &mMap))) {
32 return InvalidToWrExternalImage();
34 mLocked = true;
37 return RawDataToWrExternalImage(mMap.mData,
38 mMap.mStride * mSurface->GetSize().height);
41 void RenderSharedSurfaceTextureHost::Unlock() {
42 if (mLocked) {
43 mSurface->Unmap();
44 mLocked = false;
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) {
65 if (NS_WARN_IF(
66 !mSurface->Map(gfx::DataSourceSurface::MapType::READ, &mMap))) {
67 return false;
69 aPlaneInfo.mData = mMap.mData;
70 aPlaneInfo.mStride = mMap.mStride;
71 aPlaneInfo.mSize = mSurface->GetSize();
72 return true;
75 void RenderSharedSurfaceTextureHost::UnmapPlanes() { mSurface->Unmap(); }
77 } // namespace wr
78 } // namespace mozilla