2020-02-06 15:15:02 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2020-06-21 13:59:17 +00:00
|
|
|
#include "DMABUFSurfaceImage.h"
|
2020-12-08 15:26:09 +00:00
|
|
|
#include "mozilla/widget/DMABufSurface.h"
|
2020-02-06 15:15:02 +00:00
|
|
|
#include "mozilla/layers/CompositableClient.h"
|
|
|
|
#include "mozilla/layers/CompositableForwarder.h"
|
2020-06-21 13:59:17 +00:00
|
|
|
#include "mozilla/layers/DMABUFTextureClientOGL.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/layers/TextureForwarder.h"
|
2021-07-15 16:19:51 +00:00
|
|
|
#include "mozilla/ScopeExit.h"
|
|
|
|
#include "mozilla/StaticMutex.h"
|
|
|
|
#include "GLContext.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "GLBlitHelper.h"
|
|
|
|
#include "GLReadTexImageHelper.h"
|
|
|
|
#include "GLContextTypes.h" // for GLContext, etc
|
|
|
|
#include "GLContextEGL.h"
|
|
|
|
#include "GLContextProvider.h"
|
|
|
|
#include "ScopedGLHelpers.h"
|
2020-02-06 15:15:02 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::gfx;
|
2021-07-15 16:19:51 +00:00
|
|
|
using namespace mozilla::gl;
|
2020-02-06 15:15:02 +00:00
|
|
|
|
2020-12-08 15:26:09 +00:00
|
|
|
DMABUFSurfaceImage::DMABUFSurfaceImage(DMABufSurface* aSurface)
|
|
|
|
: Image(nullptr, ImageFormat::DMABUF), mSurface(aSurface) {
|
2022-01-24 11:59:42 +00:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mSurface->IsGlobalRefSet(),
|
|
|
|
"DMABufSurface must be marked as used!");
|
2020-12-08 15:26:09 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 11:59:42 +00:00
|
|
|
DMABUFSurfaceImage::~DMABUFSurfaceImage() {
|
|
|
|
// Unref as we're done with this surface.
|
|
|
|
mSurface->GlobalRefRelease();
|
|
|
|
}
|
2020-12-08 15:26:09 +00:00
|
|
|
|
2021-07-15 16:19:51 +00:00
|
|
|
already_AddRefed<gfx::SourceSurface> DMABUFSurfaceImage::GetAsSourceSurface() {
|
2022-06-06 13:31:03 +00:00
|
|
|
return mSurface->GetAsSourceSurface();
|
2021-07-15 16:19:51 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 13:59:17 +00:00
|
|
|
TextureClient* DMABUFSurfaceImage::GetTextureClient(
|
2020-02-06 15:15:02 +00:00
|
|
|
KnowsCompositor* aKnowsCompositor) {
|
|
|
|
if (!mTextureClient) {
|
|
|
|
BackendType backend = BackendType::NONE;
|
|
|
|
mTextureClient = TextureClient::CreateWithData(
|
2020-06-21 13:59:17 +00:00
|
|
|
DMABUFTextureData::Create(mSurface, backend), TextureFlags::DEFAULT,
|
|
|
|
aKnowsCompositor->GetTextureForwarder());
|
2020-02-06 15:15:02 +00:00
|
|
|
}
|
|
|
|
return mTextureClient;
|
|
|
|
}
|
2020-12-08 15:26:09 +00:00
|
|
|
|
|
|
|
gfx::IntSize DMABUFSurfaceImage::GetSize() const {
|
|
|
|
return gfx::IntSize::Truncate(mSurface->GetWidth(), mSurface->GetHeight());
|
|
|
|
}
|