| 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 |
|
| 61 |
GrBackendFormat backendFormat() const override { return GrVkTexture::backendFormat(); } |
| 62 |
|
| 63 |
protected: |
| 64 |
void onAbandon() override { |
| 65 |
// In order to correctly handle calling texture idle procs, GrVkTexture must go first. |
| 66 |
GrVkTexture::onAbandon(); |
| 67 |
GrVkRenderTarget::onAbandon(); |
| 68 |
} |
| 69 |
|
| 70 |
void onRelease() override { |
| 71 |
// In order to correctly handle calling texture idle procs, GrVkTexture must go first. |
| 72 |
GrVkTexture::onRelease(); |
| 73 |
GrVkRenderTarget::onRelease(); |
| 74 |
} |
| 75 |
|
| 76 |
private: |
| 77 |
GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 78 |
skgpu::Budgeted budgeted, |
| 79 |
SkISize dimensions, |
| 80 |
sk_sp<GrVkImage> texture, |
| 81 |
sk_sp<GrVkImage> colorAttachment, |
| 82 |
sk_sp<GrVkImage> resolveAttachment, |
| 83 |
GrMipmapStatus, |
| 84 |
std::string_view label); |
| 85 |
|
| 86 |
GrVkTextureRenderTarget(GrVkGpu* gpu, |
| 87 |
SkISize dimensions, |
| 88 |
sk_sp<GrVkImage> texture, |
| 89 |
sk_sp<GrVkImage> colorAttachment, |
| 90 |
sk_sp<GrVkImage> resolveAttachment, |
| 91 |
GrMipmapStatus, |
| 92 |
GrWrapCacheable, |
| 93 |
std::string_view label); |
| 94 |
|
| 95 |
size_t onGpuMemorySize() const override; |
| 96 |
|
| 97 |
void onSetLabel() override{} |
| 98 |
|
| 99 |
// In Vulkan we call the release proc after we are finished with the underlying |
| 100 |
// GrVkImage::Resource object (which occurs after the GPU has finished all work on it). |
| 101 |
void onSetRelease(sk_sp<RefCntedReleaseProc> releaseHelper) override { |
| 102 |
// Forward the release proc on to GrVkImage |
| 103 |
GrVkTexture::onSetRelease(std::move(releaseHelper)); |
| 104 |
} |
| 105 |
}; |
| 106 |
|
| 107 |
#ifdef SK_BUILD_FOR_WIN |
| 108 |
#pragma warning(pop) |
| 109 |
#endif |
| 110 |
|
| 111 |
#endif |