Bug 1842773 - Part 11: Make DataView byteOffset and byteLength accessors aware of...
[gecko.git] / gfx / webrender_bindings / RenderDcompSurfaceTextureHost.cpp
blob51e12d6ace85141878d8e4c4ad01770c6536442a
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "RenderDcompSurfaceTextureHost.h"
8 #include <dcomp.h>
10 #define LOG(msg, ...) \
11 MOZ_LOG(gDcompSurface, LogLevel::Debug, \
12 ("RenderDcompSurfaceTextureHost=%p, handle=%p, size=[%u,%u] " msg, \
13 this, this->mHandle, this->mSize.Width(), this->mSize.Height(), \
14 ##__VA_ARGS__))
16 namespace mozilla::wr {
18 RenderDcompSurfaceTextureHost::RenderDcompSurfaceTextureHost(
19 HANDLE aHandle, gfx::IntSize aSize, gfx::SurfaceFormat aFormat)
20 : mHandle(aHandle), mSize(aSize), mFormat(aFormat) {
21 MOZ_ASSERT(aHandle && aHandle != INVALID_HANDLE_VALUE);
24 IDCompositionSurface* RenderDcompSurfaceTextureHost::CreateSurfaceFromDevice(
25 IDCompositionDevice* aDevice) {
26 // Already created surface, no need to recreate it again.
27 if (mDcompSurface) {
28 return mDcompSurface;
31 auto* surface =
32 static_cast<IDCompositionSurface**>(getter_AddRefs(mDcompSurface));
33 auto hr = aDevice->CreateSurfaceFromHandle(
34 mHandle, reinterpret_cast<IUnknown**>(surface));
35 if (FAILED(hr)) {
36 LOG("Failed to create surface from Dcomp handle %p, hr=%lx", mHandle, hr);
37 return nullptr;
39 LOG("Created surface %p correctly", surface);
40 return mDcompSurface;
43 } // namespace mozilla::wr
45 #undef LOG