RenderDcompSurfaceTextureHost.cpp (1626B)
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/. */ 5 6 #include "RenderDcompSurfaceTextureHost.h" 7 8 #include <dcomp.h> 9 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__)) 15 16 namespace mozilla::wr { 17 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); 22 } 23 24 IDCompositionSurface* RenderDcompSurfaceTextureHost::CreateSurfaceFromDevice( 25 IDCompositionDevice* aDevice) { 26 // Already created surface, no need to recreate it again. 27 if (mDcompSurface) { 28 return mDcompSurface; 29 } 30 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; 38 } 39 LOG("Created surface %p correctly", surface); 40 return mDcompSurface; 41 } 42 43 } // namespace mozilla::wr 44 45 #undef LOG