1 /* 2 * Copyright 2020 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9 #ifndef GrD3DTextureRenderTarget_DEFINED 10 #define GrD3DTextureRenderTarget_DEFINED 11 12 #include "include/gpu/ganesh/d3d/GrD3DTypes.h" 13 #include "src/gpu/ganesh/d3d/GrD3DRenderTarget.h" 14 #include "src/gpu/ganesh/d3d/GrD3DTexture.h" 15 16 class GrD3DGpu; 17 18 #ifdef SK_BUILD_FOR_WIN 19 // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance. 20 #pragma warning(push) 21 #pragma warning(disable: 4250) 22 #endif 23 24 struct GrD3DTextureResourceInfo; 25 26 class GrD3DTextureRenderTarget: public GrD3DTexture, public GrD3DRenderTarget { 27 public: 28 static sk_sp<GrD3DTextureRenderTarget> MakeNewTextureRenderTarget(GrD3DGpu*, 29 skgpu::Budgeted, 30 SkISize dimensions, 31 int sampleCnt, 32 const D3D12_RESOURCE_DESC&, 33 GrProtected isProtected, 34 GrMipmapStatus, 35 std::string_view label); 36 37 static sk_sp<GrD3DTextureRenderTarget> MakeWrappedTextureRenderTarget( 38 GrD3DGpu*, SkISize dimensions, int sampleCnt, GrWrapCacheable, 39 const GrD3DTextureResourceInfo&, sk_sp<GrD3DResourceState>); 40 backendFormat()41 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); } 42 43 protected: onAbandon()44 void onAbandon() override { 45 // In order to correctly handle calling texture idle procs, GrD3DTexture must go first. 46 GrD3DTexture::onAbandon(); 47 GrD3DRenderTarget::onAbandon(); 48 } 49 onRelease()50 void onRelease() override { 51 // In order to correctly handle calling texture idle procs, GrD3DTexture must go first. 52 GrD3DTexture::onRelease(); 53 GrD3DRenderTarget::onRelease(); 54 } 55 56 private: 57 // MSAA, not-wrapped 58 GrD3DTextureRenderTarget(GrD3DGpu* gpu, 59 skgpu::Budgeted budgeted, 60 SkISize dimensions, 61 const GrD3DTextureResourceInfo& info, 62 sk_sp<GrD3DResourceState> state, 63 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 64 const GrD3DTextureResourceInfo& msaaInfo, 65 sk_sp<GrD3DResourceState> msaaState, 66 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView, 67 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView, 68 GrMipmapStatus, 69 std::string_view label); 70 71 // non-MSAA, not-wrapped 72 GrD3DTextureRenderTarget(GrD3DGpu* gpu, 73 skgpu::Budgeted budgeted, 74 SkISize dimensions, 75 const GrD3DTextureResourceInfo& info, 76 sk_sp<GrD3DResourceState> state, 77 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 78 const GrD3DDescriptorHeap::CPUHandle& renderTargetView, 79 GrMipmapStatus, 80 std::string_view label); 81 82 // MSAA, wrapped 83 GrD3DTextureRenderTarget(GrD3DGpu* gpu, 84 SkISize dimensions, 85 const GrD3DTextureResourceInfo& info, 86 sk_sp<GrD3DResourceState> state, 87 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 88 const GrD3DTextureResourceInfo& msaaInfo, 89 sk_sp<GrD3DResourceState> msaaState, 90 const GrD3DDescriptorHeap::CPUHandle& colorRenderTargetView, 91 const GrD3DDescriptorHeap::CPUHandle& resolveRenderTargetView, 92 GrMipmapStatus, 93 GrWrapCacheable, 94 std::string_view label); 95 96 // non-MSAA, wrapped 97 GrD3DTextureRenderTarget(GrD3DGpu* gpu, 98 SkISize dimensions, 99 const GrD3DTextureResourceInfo& info, 100 sk_sp<GrD3DResourceState> state, 101 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 102 const GrD3DDescriptorHeap::CPUHandle& renderTargetView, 103 GrMipmapStatus, 104 GrWrapCacheable, 105 std::string_view label); 106 107 // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory. 108 size_t onGpuMemorySize() const override; 109 110 void onSetLabel() override; 111 112 // In Direct3D we call the release proc after we are finished with the underlying 113 // GrD3DImage::Resource object (which occurs after the GPU has finished all work on it). onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper)114 void onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper) override { 115 // Forward the release proc on to GrD3DImage 116 this->setResourceRelease(std::move(releaseHelper)); 117 } 118 }; 119 120 #ifdef SK_BUILD_FOR_WIN 121 #pragma warning(pop) 122 #endif 123 124 #endif 125