Hash :
ff32734d
Author :
Date :
2018-02-22T18:20:37
Support EGLStream from B8G8R8A8_UNORM D3D11Texture. Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1415754 BUG=angleproject:2368 Change-Id: Ic2c71b36e7b08560e158fd3dbf10b2fe225f1364 Reviewed-on: https://chromium-review.googlesource.com/935148 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
//
// Copyright (c) 2016 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// StreamProducerD3DTexture.cpp: Implements the stream producer for D3D11 textures
#include "libANGLE/renderer/d3d/d3d11/StreamProducerD3DTexture.h"
#include "common/utilities.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
namespace rx
{
namespace
{
egl::Error GetGLDescFromTex(ID3D11Texture2D *const tex,
const UINT planeIndex,
egl::Stream::GLTextureDescription *const out)
{
if (!tex)
return egl::EglBadParameter() << "Texture is null";
D3D11_TEXTURE2D_DESC desc;
tex->GetDesc(&desc);
if (desc.Width < 1 || desc.Height < 1)
return egl::EglBadParameter() << "Width or height < 1";
out->width = desc.Width;
out->height = desc.Height;
out->mipLevels = 0;
UINT maxPlaneIndex = 0;
switch (desc.Format)
{
case DXGI_FORMAT_NV12:
// The UV plane of NV12 textures has half the width/height of the Y plane
if ((desc.Width % 2) != 0 || (desc.Height % 2) != 0)
return egl::EglBadParameter() << "NV12 tetxures must have even width and height.";
maxPlaneIndex = 1;
if (planeIndex == 0)
{
out->internalFormat = GL_R8;
}
else
{
out->internalFormat = GL_RG8;
out->width /= 2;
out->height /= 2;
}
break;
case DXGI_FORMAT_R8_UNORM:
out->internalFormat = GL_R8;
break;
case DXGI_FORMAT_R8G8_UNORM:
out->internalFormat = GL_RG8;
break;
case DXGI_FORMAT_R8G8B8A8_UNORM:
out->internalFormat = GL_RGBA8;
break;
case DXGI_FORMAT_B8G8R8A8_UNORM:
out->internalFormat = GL_BGRA8_EXT;
break;
default:
return egl::EglBadParameter() << "Unsupported format";
}
if (planeIndex > maxPlaneIndex) // Just kidding, there's no plane out there.
return egl::EglBadParameter() << "Plane out of range";
return egl::NoError();
}
} // namespace
StreamProducerD3DTexture::StreamProducerD3DTexture(Renderer11 *renderer)
: mRenderer(renderer), mTexture(nullptr), mArraySlice(0), mPlaneOffset(0)
{
}
StreamProducerD3DTexture::~StreamProducerD3DTexture()
{
SafeRelease(mTexture);
}
egl::Error StreamProducerD3DTexture::validateD3DTexture(void *pointer,
const egl::AttributeMap &attributes) const
{
ID3D11Texture2D *textureD3D = static_cast<ID3D11Texture2D *>(pointer);
// Check that the texture originated from our device
ID3D11Device *device;
textureD3D->GetDevice(&device);
if (device != mRenderer->getDevice())
{
return egl::EglBadParameter() << "Texture not created on ANGLE D3D device";
}
const auto planeId = static_cast<UINT>(attributes.get(EGL_NATIVE_BUFFER_PLANE_OFFSET_IMG, 0));
egl::Stream::GLTextureDescription unused;
return GetGLDescFromTex(textureD3D, planeId, &unused);
}
void StreamProducerD3DTexture::postD3DTexture(void *pointer, const egl::AttributeMap &attributes)
{
ASSERT(pointer != nullptr);
ID3D11Texture2D *textureD3D = static_cast<ID3D11Texture2D *>(pointer);
// Release the previous texture if there is one
SafeRelease(mTexture);
mTexture = textureD3D;
mTexture->AddRef();
mPlaneOffset = static_cast<UINT>(attributes.get(EGL_NATIVE_BUFFER_PLANE_OFFSET_IMG, 0));
mArraySlice = static_cast<UINT>(attributes.get(EGL_D3D_TEXTURE_SUBRESOURCE_ID_ANGLE, 0));
}
egl::Stream::GLTextureDescription StreamProducerD3DTexture::getGLFrameDescription(int planeIndex)
{
const auto planeOffsetIndex = static_cast<UINT>(planeIndex + mPlaneOffset);
egl::Stream::GLTextureDescription ret;
ANGLE_SWALLOW_ERR(GetGLDescFromTex(mTexture, planeOffsetIndex, &ret));
return ret;
}
ID3D11Texture2D *StreamProducerD3DTexture::getD3DTexture()
{
return mTexture;
}
UINT StreamProducerD3DTexture::getArraySlice()
{
return mArraySlice;
}
} // namespace rx