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