• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 // EGLImageD3D.cpp: Implements the rx::EGLImageD3D class, the D3D implementation of EGL images
8 
9 #include "libANGLE/renderer/d3d/EGLImageD3D.h"
10 
11 #include "common/debug.h"
12 #include "common/utilities.h"
13 #include "libANGLE/AttributeMap.h"
14 #include "libANGLE/Context.h"
15 #include "libANGLE/Texture.h"
16 #include "libANGLE/renderer/d3d/RenderTargetD3D.h"
17 #include "libANGLE/renderer/d3d/RenderbufferD3D.h"
18 #include "libANGLE/renderer/d3d/RendererD3D.h"
19 #include "libANGLE/renderer/d3d/TextureD3D.h"
20 #include "libANGLE/renderer/d3d/TextureStorage.h"
21 
22 #include <EGL/eglext.h>
23 
24 namespace rx
25 {
26 
EGLImageD3D(const egl::ImageState & state,EGLenum target,const egl::AttributeMap & attribs,RendererD3D * renderer)27 EGLImageD3D::EGLImageD3D(const egl::ImageState &state,
28                          EGLenum target,
29                          const egl::AttributeMap &attribs,
30                          RendererD3D *renderer)
31     : ImageImpl(state), mRenderer(renderer), mRenderTarget(nullptr)
32 {
33     ASSERT(renderer != nullptr);
34 }
35 
~EGLImageD3D()36 EGLImageD3D::~EGLImageD3D()
37 {
38     SafeDelete(mRenderTarget);
39 }
40 
initialize(const egl::Display * display)41 egl::Error EGLImageD3D::initialize(const egl::Display *display)
42 {
43     return egl::NoError();
44 }
45 
orphan(const gl::Context * context,egl::ImageSibling * sibling)46 angle::Result EGLImageD3D::orphan(const gl::Context *context, egl::ImageSibling *sibling)
47 {
48     if (sibling == mState.source)
49     {
50         ANGLE_TRY(copyToLocalRendertarget(context));
51     }
52 
53     return angle::Result::Continue;
54 }
55 
getRenderTarget(const gl::Context * context,RenderTargetD3D ** outRT) const56 angle::Result EGLImageD3D::getRenderTarget(const gl::Context *context,
57                                            RenderTargetD3D **outRT) const
58 {
59     if (mState.source != nullptr)
60     {
61         ASSERT(!mRenderTarget);
62         FramebufferAttachmentRenderTarget *rt = nullptr;
63         ANGLE_TRY(
64             mState.source->getAttachmentRenderTarget(context, GL_NONE, mState.imageIndex, 0, &rt));
65         *outRT = static_cast<RenderTargetD3D *>(rt);
66         return angle::Result::Continue;
67     }
68 
69     ASSERT(mRenderTarget);
70     *outRT = mRenderTarget;
71     return angle::Result::Continue;
72 }
73 
copyToLocalRendertarget(const gl::Context * context)74 angle::Result EGLImageD3D::copyToLocalRendertarget(const gl::Context *context)
75 {
76     ASSERT(mState.source != nullptr);
77     ASSERT(mRenderTarget == nullptr);
78 
79     RenderTargetD3D *curRenderTarget = nullptr;
80     ANGLE_TRY(getRenderTarget(context, &curRenderTarget));
81 
82     // Invalidate FBOs with this Image attached. Only currently applies to D3D11.
83     for (egl::ImageSibling *target : mState.targets)
84     {
85         target->onStateChange(angle::SubjectMessage::SubjectChanged);
86     }
87 
88     return mRenderer->createRenderTargetCopy(context, curRenderTarget, &mRenderTarget);
89 }
90 }  // namespace rx
91