SourceSurfaceD3D11.cpp (2149B)
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/. */ 6 7 #include "SourceSurfaceD3D11.h" 8 9 namespace mozilla { 10 namespace gfx { 11 12 /* static */ 13 RefPtr<SourceSurfaceD3D11> SourceSurfaceD3D11::Create( 14 ID3D11Texture2D* aTexture, const uint32_t aArrayIndex, 15 const gfx::ColorSpace2 aColorSpace, const gfx::ColorRange aColorRange, 16 const Maybe<layers::CompositeProcessFencesHolderId> aFencesHolderId) { 17 MOZ_ASSERT(aTexture); 18 19 if (!aTexture) { 20 return nullptr; 21 } 22 23 CD3D11_TEXTURE2D_DESC desc; 24 aTexture->GetDesc(&desc); 25 26 if (desc.Format != DXGI_FORMAT_B8G8R8A8_UNORM && 27 desc.Format != DXGI_FORMAT_NV12 && desc.Format != DXGI_FORMAT_P010 && 28 desc.Format != DXGI_FORMAT_P016) { 29 MOZ_ASSERT_UNREACHABLE("unexpected to be called"); 30 return nullptr; 31 } 32 33 return MakeAndAddRef<SourceSurfaceD3D11>( 34 SurfaceFormat::B8G8R8A8, IntSize(desc.Width, desc.Height), aTexture, 35 aArrayIndex, aColorSpace, aColorRange, aFencesHolderId); 36 } 37 38 SourceSurfaceD3D11::SourceSurfaceD3D11( 39 const SurfaceFormat aFormat, const IntSize aSize, ID3D11Texture2D* aTexture, 40 const uint32_t aArrayIndex, const gfx::ColorSpace2 aColorSpace, 41 const gfx::ColorRange aColorRange, 42 const Maybe<layers::CompositeProcessFencesHolderId> aFencesHolderId) 43 : mFormat(aFormat), 44 mSize(aSize), 45 mTexture(aTexture), 46 mArrayIndex(aArrayIndex), 47 mColorSpace(aColorSpace), 48 mColorRange(aColorRange), 49 mFencesHolderId(aFencesHolderId) {} 50 51 SourceSurfaceD3D11::~SourceSurfaceD3D11() {} 52 53 bool SourceSurfaceD3D11::IsValid() const { return true; } 54 55 already_AddRefed<DataSourceSurface> SourceSurfaceD3D11::GetDataSurface() { 56 RefPtr<DataSourceSurface> src = 57 Factory::CreateBGRA8DataSourceSurfaceForD3D11Texture( 58 mTexture, mArrayIndex, mColorSpace, mColorRange); 59 return src.forget(); 60 } 61 62 } // namespace gfx 63 } // namespace mozilla