Bug 1719855 - Clean up code whether to fire a pointercancel event. r=botond
[gecko.git] / gfx / webrender_bindings / RenderSharedSurfaceTextureHost.cpp
blobdb085f8f2f9b203afc4bd7b4b5b6b952b3601407
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(uint8_t aChannelIndex,
28 gl::GLContext* aGL) {
29 if (!mLocked) {
30 if (NS_WARN_IF(
31 !mSurface->Map(gfx::DataSourceSurface::MapType::READ, &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