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 #ifndef GrD3DTexture_DEFINED 9 #define GrD3DTexture_DEFINED 10 11 #include "src/core/SkLRUCache.h" 12 #include "src/gpu/GrSamplerState.h" 13 #include "src/gpu/GrTexture.h" 14 #include "src/gpu/d3d/GrD3DDescriptorHeap.h" 15 #include "src/gpu/d3d/GrD3DTextureResource.h" 16 17 class GrD3DTexture : public GrTexture, public virtual GrD3DTextureResource { 18 public: 19 static sk_sp<GrD3DTexture> MakeNewTexture(GrD3DGpu*, 20 SkBudgeted, 21 SkISize dimensions, 22 const D3D12_RESOURCE_DESC&, 23 GrProtected, 24 GrMipmapStatus); 25 26 static sk_sp<GrD3DTexture> MakeWrappedTexture(GrD3DGpu*, 27 SkISize dimensions, 28 GrWrapCacheable, 29 GrIOType, 30 const GrD3DTextureResourceInfo&, 31 sk_sp<GrD3DResourceState>); 32 33 static sk_sp<GrD3DTexture> MakeAliasingTexture(GrD3DGpu*, 34 sk_sp<GrD3DTexture>, 35 const D3D12_RESOURCE_DESC& newDesc, 36 D3D12_RESOURCE_STATES); 37 ~GrD3DTexture()38 ~GrD3DTexture() override {} 39 40 GrBackendTexture getBackendTexture() const override; 41 backendFormat()42 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); } shaderResourceView()43 D3D12_CPU_DESCRIPTOR_HANDLE shaderResourceView() { return fShaderResourceView.fHandle; } 44 textureParamsModified()45 void textureParamsModified() override {} 46 47 protected: 48 GrD3DTexture(GrD3DGpu*, 49 SkISize dimensions, 50 const GrD3DTextureResourceInfo&, 51 sk_sp<GrD3DResourceState>, 52 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 53 GrMipmapStatus); 54 55 GrD3DGpu* getD3DGpu() const; 56 57 void onAbandon() override; 58 void onRelease() override; 59 onStealBackendTexture(GrBackendTexture *,SkImage::BackendTextureReleaseProc *)60 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { 61 return false; 62 } 63 64 private: 65 GrD3DTexture(GrD3DGpu*, SkBudgeted, SkISize dimensions, const GrD3DTextureResourceInfo&, 66 sk_sp<GrD3DResourceState>, 67 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 68 GrMipmapStatus); 69 GrD3DTexture(GrD3DGpu*, SkISize dimensions, const GrD3DTextureResourceInfo&, 70 sk_sp<GrD3DResourceState>, 71 const GrD3DDescriptorHeap::CPUHandle& shaderResourceView, 72 GrMipmapStatus, GrWrapCacheable, GrIOType); 73 74 // In D3D we call the release proc after we are finished with the underlying 75 // GrSurfaceResource::Resource object (which occurs after the GPU has finished all work on it). onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper)76 void onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper) override { 77 // Forward the release proc on to GrSurfaceResource 78 this->setResourceRelease(std::move(releaseHelper)); 79 } 80 81 struct SamplerHash { operatorSamplerHash82 uint32_t operator()(GrSamplerState state) const { return state.asIndex(); } 83 }; 84 85 GrD3DDescriptorHeap::CPUHandle fShaderResourceView; 86 87 using INHERITED = GrTexture; 88 }; 89 90 #endif 91