Bug 1839315: part 4) Link from `SheetLoadData::mWasAlternate` to spec. r=emilio DONTBUILD
[gecko.git] / gfx / layers / DMABUFSurfaceImage.cpp
blob8d9234bfd21af36f5e34b34af2aa41f38a3b6b9e
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 "DMABUFSurfaceImage.h"
8 #include "mozilla/widget/DMABufSurface.h"
9 #include "mozilla/layers/CompositableClient.h"
10 #include "mozilla/layers/CompositableForwarder.h"
11 #include "mozilla/layers/DMABUFTextureClientOGL.h"
12 #include "mozilla/layers/TextureForwarder.h"
13 #include "mozilla/ScopeExit.h"
14 #include "mozilla/StaticMutex.h"
15 #include "GLContext.h"
16 #include "GLContextProvider.h"
17 #include "GLBlitHelper.h"
18 #include "GLReadTexImageHelper.h"
19 #include "GLContextTypes.h" // for GLContext, etc
20 #include "GLContextEGL.h"
21 #include "GLContextProvider.h"
22 #include "ScopedGLHelpers.h"
24 using namespace mozilla;
25 using namespace mozilla::layers;
26 using namespace mozilla::gfx;
27 using namespace mozilla::gl;
29 #ifdef MOZ_LOGGING
30 # undef DMABUF_LOG
31 extern mozilla::LazyLogModule gDmabufLog;
32 # define DMABUF_LOG(str, ...) \
33 MOZ_LOG(gDmabufLog, mozilla::LogLevel::Debug, (str, ##__VA_ARGS__))
34 #else
35 # define DMABUF_LOG(args)
36 #endif /* MOZ_LOGGING */
38 DMABUFSurfaceImage::DMABUFSurfaceImage(DMABufSurface* aSurface)
39 : Image(nullptr, ImageFormat::DMABUF), mSurface(aSurface) {
40 DMABUF_LOG("DMABUFSurfaceImage::DMABUFSurfaceImage (%p) aSurface %p UID %d\n",
41 this, aSurface, aSurface->GetUID());
42 mSurface->GlobalRefAdd();
45 DMABUFSurfaceImage::~DMABUFSurfaceImage() {
46 DMABUF_LOG(
47 "DMABUFSurfaceImage::~DMABUFSurfaceImage (%p) mSurface %p UID %d\n", this,
48 (void*)mSurface.get(), mSurface->GetUID());
49 mSurface->GlobalRefRelease();
52 already_AddRefed<gfx::SourceSurface> DMABUFSurfaceImage::GetAsSourceSurface() {
53 return mSurface->GetAsSourceSurface();
56 TextureClient* DMABUFSurfaceImage::GetTextureClient(
57 KnowsCompositor* aKnowsCompositor) {
58 if (!mTextureClient) {
59 BackendType backend = BackendType::NONE;
60 mTextureClient = TextureClient::CreateWithData(
61 DMABUFTextureData::Create(mSurface, backend), TextureFlags::DEFAULT,
62 aKnowsCompositor->GetTextureForwarder());
64 return mTextureClient;
67 gfx::IntSize DMABUFSurfaceImage::GetSize() const {
68 return gfx::IntSize::Truncate(mSurface->GetWidth(), mSurface->GetHeight());