gecko-dev/gfx/webrender_bindings/RenderDcompSurfaceTextureHost.cpp
alwu efe35b01d5 Bug 1771011 - part2 : wrap media engine's dcomp handle, and use it on our gfx pipeline in the GPU process.r=jolin,sotaro
In this patch, we ask the media engine to return a handle for shareable
dcomp surface, which will then be packaged into a new texture data type
and being shared with the GPU process via the video bridge.

DcompSurfaceImage is the image which contains the handle texture data,
which doesn't support being accessed in the content process. When the
compositor uploads the image to the GPU process, the corresponding
texture host will be created.

The render texture host will be created by that texture host, and it
will be used in DCLayerTree. In DCLayerTree, we create a new type of
surface for our dcomp handle. DCSurfaceHandle will ask the render
texture host to reconstruct the surface by the handle shared from the
remote process (the handle is actually duplicated to the parent process
first due to the sandbox policy, and then be duplicated to the GPU
process later)

DCSurfaceHandle will attach that surface to its visual in order to
display the video frame directly. In the whole process, it's not
possible for Gecko to access any decoded video data which is protected by the
media engine itself.

Depends on D149941

Differential Revision: https://phabricator.services.mozilla.com/D151019
2022-08-13 23:48:07 +00:00

51 lines
1.7 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "RenderDcompSurfaceTextureHost.h"
#undef _WIN32_WINNT
#define _WIN32_WINNT _WIN32_WINNT_WINBLUE
#undef NTDDI_VERSION
#define NTDDI_VERSION NTDDI_WINBLUE
#include <dcomp.h>
#define LOG(msg, ...) \
MOZ_LOG(gDcompSurface, LogLevel::Debug, \
("RenderDcompSurfaceTextureHost=%p, handle=%p, size=[%u,%u] " msg, \
this, this->mHandle, this->mSize.Width(), this->mSize.Height(), \
##__VA_ARGS__))
namespace mozilla::wr {
RenderDcompSurfaceTextureHost::RenderDcompSurfaceTextureHost(
HANDLE aHandle, gfx::IntSize aSize, gfx::SurfaceFormat aFormat)
: mHandle(aHandle), mSize(aSize), mFormat(aFormat) {
MOZ_ASSERT(aHandle && aHandle != INVALID_HANDLE_VALUE);
}
IDCompositionSurface* RenderDcompSurfaceTextureHost::CreateSurfaceFromDevice(
IDCompositionDevice* aDevice) {
// Already created surface, no need to recreate it again.
if (mDcompSurface) {
return mDcompSurface;
}
auto* surface =
static_cast<IDCompositionSurface**>(getter_AddRefs(mDcompSurface));
auto hr = aDevice->CreateSurfaceFromHandle(
mHandle, reinterpret_cast<IUnknown**>(surface));
if (FAILED(hr)) {
LOG("Failed to create surface from Dcomp handle %p, hr=%lx", mHandle, hr);
return nullptr;
}
LOG("Created surface %p correctly", surface);
return mDcompSurface;
}
} // namespace mozilla::wr
#undef LOG