Backed out 2 changesets (bug 1931901) for causing build bustages in TelemetryScalar...
[gecko.git] / gfx / layers / DMABUFSurfaceImage.cpp
blob46c96554949f6554cb12233a1a4b4c9cb29c9607
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 nsresult DMABUFSurfaceImage::BuildSurfaceDescriptorBuffer(
57 SurfaceDescriptorBuffer& aSdBuffer, BuildSdbFlags aFlags,
58 const std::function<MemoryOrShmem(uint32_t)>& aAllocate) {
59 return mSurface->BuildSurfaceDescriptorBuffer(aSdBuffer, aFlags, aAllocate);
62 TextureClient* DMABUFSurfaceImage::GetTextureClient(
63 KnowsCompositor* aKnowsCompositor) {
64 if (!mTextureClient) {
65 BackendType backend = BackendType::NONE;
66 mTextureClient = TextureClient::CreateWithData(
67 DMABUFTextureData::Create(mSurface, backend), TextureFlags::DEFAULT,
68 aKnowsCompositor->GetTextureForwarder());
70 return mTextureClient;
73 gfx::IntSize DMABUFSurfaceImage::GetSize() const {
74 return gfx::IntSize::Truncate(mSurface->GetWidth(), mSurface->GetHeight());