1 /* 2 * Copyright 2015 Google Inc. 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 GrVkTextureRenderTarget_DEFINED 9 #define GrVkTextureRenderTarget_DEFINED 10 11 #include "include/core/SkRefCnt.h" 12 #include "include/gpu/ganesh/GrBackendSurface.h" 13 #include "include/gpu/ganesh/GrTypes.h" 14 #include "include/private/gpu/ganesh/GrTypesPriv.h" 15 #include "include/private/gpu/vk/SkiaVulkan.h" 16 #include "src/gpu/ganesh/vk/GrVkRenderTarget.h" 17 #include "src/gpu/ganesh/vk/GrVkTexture.h" 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <string_view> 22 #include <utility> 23 24 class GrVkGpu; 25 class GrVkImage; 26 struct GrVkImageInfo; 27 struct SkISize; 28 29 namespace skgpu { 30 class MutableTextureState; 31 enum class Budgeted : bool; 32 } // namespace skgpu 33 34 #ifdef SK_BUILD_FOR_WIN 35 // Windows gives bogus warnings about inheriting asTexture/asRenderTarget via dominance. 36 #pragma warning(push) 37 #pragma warning(disable: 4250) 38 #endif 39 40 class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget { 41 public: 42 static sk_sp<GrVkTextureRenderTarget> MakeNewTextureRenderTarget(GrVkGpu* gpu, 43 skgpu::Budgeted budgeted, 44 SkISize dimensions, 45 VkFormat format, 46 uint32_t mipLevels, 47 int sampleCnt, 48 GrMipmapStatus mipmapStatus, 49 GrProtected isProtected, 50 std::string_view label); 51 52 static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget( 53 GrVkGpu*, 54 SkISize dimensions, 55 int sampleCnt, 56 GrWrapOwnership, 57 GrWrapCacheable, 58 const GrVkImageInfo&, 59 sk_sp<skgpu::MutableTextureState>); 60 backendFormat()61 GrBackendFormat backendFormat() const override { return GrVkTexture::backendFormat(); } 62 63 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; 64 65 protected: onAbandon()66 void onAbandon() override { 67 // In order to correctly handle calling texture idle procs, GrVkTexture must go first. 68 GrVkTexture::onAbandon(); 69 GrVkRenderTarget::onAbandon(); 70 } 71 onRelease()72 void onRelease() override { 73 // In order to correctly handle calling texture idle procs, GrVkTexture must go first. 74 GrVkTexture::onRelease(); 75 GrVkRenderTarget::onRelease(); 76 } 77 78 private: 79 GrVkTextureRenderTarget(GrVkGpu* gpu, 80 skgpu::Budgeted budgeted, 81 SkISize dimensions, 82 sk_sp<GrVkImage> texture, 83 sk_sp<GrVkImage> colorAttachment, 84 sk_sp<GrVkImage> resolveAttachment, 85 GrMipmapStatus, 86 std::string_view label); 87 88 GrVkTextureRenderTarget(GrVkGpu* gpu, 89 SkISize dimensions, 90 sk_sp<GrVkImage> texture, 91 sk_sp<GrVkImage> colorAttachment, 92 sk_sp<GrVkImage> resolveAttachment, 93 GrMipmapStatus, 94 GrWrapCacheable, 95 std::string_view label); 96 97 size_t onGpuMemorySize() const override; 98 onSetLabel()99 void onSetLabel() override{} 100 101 // In Vulkan we call the release proc after we are finished with the underlying 102 // GrVkImage::Resource object (which occurs after the GPU has finished all work on it). onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper)103 void onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper) override { 104 // Forward the release proc on to GrVkImage 105 GrVkTexture::onSetRelease(std::move(releaseHelper)); 106 } 107 }; 108 109 #ifdef SK_BUILD_FOR_WIN 110 #pragma warning(pop) 111 #endif 112 113 #endif 114