blob: d089d441848181925a691c101446865d7416e093 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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
9#ifndef GrVkTextureRenderTarget_DEFINED
10#define GrVkTextureRenderTarget_DEFINED
11
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/gpu/vk/GrVkTypes.h"
13#include "src/gpu/vk/GrVkRenderTarget.h"
14#include "src/gpu/vk/GrVkTexture.h"
Greg Daniel6ecc9112017-06-16 16:17:03 +000015
16class GrVkGpu;
Greg Daniel164a9f02016-02-22 09:56:40 -050017
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
24class GrVkImageView;
egdanielb2df0c22016-05-13 11:30:37 -070025struct GrVkImageInfo;
Greg Daniel164a9f02016-02-22 09:56:40 -050026
27class GrVkTextureRenderTarget: public GrVkTexture, public GrVkRenderTarget {
28public:
Greg Daniele895ab22021-03-12 16:29:40 -050029 static sk_sp<GrVkTextureRenderTarget> MakeNewTextureRenderTarget(
30 GrVkGpu* gpu,
31 SkBudgeted budgeted,
32 SkISize dimensions,
33 VkFormat format,
34 uint32_t mipLevels,
35 int sampleCnt,
36 GrMipmapStatus mipmapStatus,
37 GrProtected isProtected);
Greg Daniel164a9f02016-02-22 09:56:40 -050038
Greg Daniel6c6caf42020-05-29 12:11:05 -040039 static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(
40 GrVkGpu*,
41 SkISize dimensions,
42 int sampleCnt,
43 GrWrapOwnership,
44 GrWrapCacheable,
45 const GrVkImageInfo&,
46 sk_sp<GrBackendSurfaceMutableStateImpl>);
Greg Daniel164a9f02016-02-22 09:56:40 -050047
Greg Daniele895ab22021-03-12 16:29:40 -050048 GrBackendFormat backendFormat() const override { return GrVkTexture::backendFormat(); }
Greg Daniel4065d452018-11-16 15:43:41 -050049
Greg Daniel164a9f02016-02-22 09:56:40 -050050protected:
51 void onAbandon() override {
Brian Salomon9bc76d92019-01-24 12:18:33 -050052 // In order to correctly handle calling texture idle procs, GrVkTexture must go first.
Greg Daniel164a9f02016-02-22 09:56:40 -050053 GrVkTexture::onAbandon();
Brian Salomon9bc76d92019-01-24 12:18:33 -050054 GrVkRenderTarget::onAbandon();
Greg Daniel164a9f02016-02-22 09:56:40 -050055 }
56
57 void onRelease() override {
Brian Salomon9bc76d92019-01-24 12:18:33 -050058 // In order to correctly handle calling texture idle procs, GrVkTexture must go first.
Greg Daniel164a9f02016-02-22 09:56:40 -050059 GrVkTexture::onRelease();
Brian Salomon9bc76d92019-01-24 12:18:33 -050060 GrVkRenderTarget::onRelease();
Greg Daniel164a9f02016-02-22 09:56:40 -050061 }
62
63private:
64 GrVkTextureRenderTarget(GrVkGpu* gpu,
kkinnunen2e6055b2016-04-22 01:48:29 -070065 SkBudgeted budgeted,
Brian Salomona56a7462020-02-07 14:17:25 -050066 SkISize dimensions,
Greg Daniel2bc96d62021-09-13 13:08:02 -040067 sk_sp<GrVkImage> texture,
68 sk_sp<GrVkImage> colorAttachment,
69 sk_sp<GrVkImage> resolveAttachment,
Brian Salomona6db5102020-07-21 09:56:23 -040070 GrMipmapStatus);
Greg Daniel6ecc9112017-06-16 16:17:03 +000071
kkinnunen2e6055b2016-04-22 01:48:29 -070072 GrVkTextureRenderTarget(GrVkGpu* gpu,
Brian Salomona56a7462020-02-07 14:17:25 -050073 SkISize dimensions,
Greg Daniel2bc96d62021-09-13 13:08:02 -040074 sk_sp<GrVkImage> texture,
75 sk_sp<GrVkImage> colorAttachment,
76 sk_sp<GrVkImage> resolveAttachment,
Brian Salomona6db5102020-07-21 09:56:23 -040077 GrMipmapStatus,
Brian Salomonaa6ca0a2019-01-24 16:03:07 -050078 GrWrapCacheable);
Greg Daniel164a9f02016-02-22 09:56:40 -050079
Robert Phillips646e4292017-06-13 12:44:56 -040080 size_t onGpuMemorySize() const override;
Greg Daniel2d35a1c2019-02-01 14:48:10 -050081
82 // In Vulkan we call the release proc after we are finished with the underlying
83 // GrVkImage::Resource object (which occurs after the GPU has finished all work on it).
Brian Salomonb2c5dae2019-03-04 10:25:17 -050084 void onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper) override {
Greg Daniel2d35a1c2019-02-01 14:48:10 -050085 // Forward the release proc on to GrVkImage
Greg Daniele895ab22021-03-12 16:29:40 -050086 GrVkTexture::onSetRelease(std::move(releaseHelper));
Greg Daniel2d35a1c2019-02-01 14:48:10 -050087 }
Greg Daniel164a9f02016-02-22 09:56:40 -050088};
89
Jim Van Verthd2b695a2020-09-08 11:33:12 -040090#ifdef SK_BUILD_FOR_WIN
91#pragma warning(pop)
92#endif
93
Greg Daniel164a9f02016-02-22 09:56:40 -050094#endif