blob: 97d7f0669039ab51067d8f4d533b0cb6fd4ce84b [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#ifndef GrVkTexture_DEFINED
9#define GrVkTexture_DEFINED
10
Greg Daniel164a9f02016-02-22 09:56:40 -050011#include "GrTexture.h"
12#include "GrVkImage.h"
Greg Daniel487132b2018-12-20 14:09:36 -050013#include "vk/GrVkTypes.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050014
15class GrVkGpu;
16class GrVkImageView;
egdanielb2df0c22016-05-13 11:30:37 -070017struct GrVkImageInfo;
Greg Daniel164a9f02016-02-22 09:56:40 -050018
19class GrVkTexture : public GrTexture, public virtual GrVkImage {
20public:
Greg Daniel475eb702018-09-28 14:16:50 -040021 static sk_sp<GrVkTexture> MakeNewTexture(GrVkGpu*,
22 SkBudgeted budgeted,
23 const GrSurfaceDesc&,
24 const GrVkImage::ImageDesc&,
25 GrMipMapsStatus);
halcanary9d524f22016-03-29 09:03:52 -070026
Brian Salomonc67c31c2018-12-06 10:00:03 -050027 static sk_sp<GrVkTexture> MakeWrappedTexture(GrVkGpu*, const GrSurfaceDesc&, GrWrapOwnership,
Brian Salomonfa2ebea2019-01-24 15:58:58 -050028 GrWrapCacheable, GrIOType, const GrVkImageInfo&,
29 sk_sp<GrVkImageLayout>);
Greg Daniel164a9f02016-02-22 09:56:40 -050030
31 ~GrVkTexture() override;
32
Robert Phillipsb67821d2017-12-13 15:00:45 -050033 GrBackendTexture getBackendTexture() const override;
Greg Daniel164a9f02016-02-22 09:56:40 -050034
Greg Daniel4065d452018-11-16 15:43:41 -050035 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
36
Greg Daniel164a9f02016-02-22 09:56:40 -050037 void textureParamsModified() override {}
38
Brian Osman2b23c4b2018-06-01 12:25:08 -040039 const GrVkImageView* textureView();
Greg Daniel164a9f02016-02-22 09:56:40 -050040
Greg Danielcef213c2017-04-21 11:52:27 -040041 // In Vulkan we call the release proc after we are finished with the underlying
42 // GrVkImage::Resource object (which occurs after the GPU has finsihed all work on it).
Greg Daniel6a0176b2018-01-30 09:28:44 -050043 void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) override {
Greg Danielcef213c2017-04-21 11:52:27 -040044 // Forward the release proc on to GrVkImage
Greg Daniel6a0176b2018-01-30 09:28:44 -050045 this->setResourceRelease(std::move(releaseHelper));
Greg Danielcef213c2017-04-21 11:52:27 -040046 }
47
Brian Salomon614c1a82018-12-19 15:42:06 -050048 void setIdleProc(IdleProc, void* context) override;
Brian Salomon1bf0ed82019-01-16 13:51:35 -050049 void* idleContext() const override { return fIdleProcContext; }
Brian Salomon614c1a82018-12-19 15:42:06 -050050
Greg Daniel164a9f02016-02-22 09:56:40 -050051protected:
Greg Daniel52e16d92018-04-10 09:34:07 -040052 GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp<GrVkImageLayout>,
53 const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership);
Greg Daniel164a9f02016-02-22 09:56:40 -050054
halcanary9d524f22016-03-29 09:03:52 -070055 GrVkGpu* getVkGpu() const;
Greg Daniel164a9f02016-02-22 09:56:40 -050056
57 void onAbandon() override;
58 void onRelease() override;
59
Eric Karl914a36b2017-10-12 12:44:50 -070060 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override {
61 return false;
62 }
63
Greg Daniel164a9f02016-02-22 09:56:40 -050064private:
Greg Daniel52e16d92018-04-10 09:34:07 -040065 GrVkTexture(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&, const GrVkImageInfo&,
66 sk_sp<GrVkImageLayout> layout, const GrVkImageView* imageView,
Greg Daniel0fc4d2d2017-10-12 11:23:36 -040067 GrMipMapsStatus);
Brian Salomonfa2ebea2019-01-24 15:58:58 -050068 GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp<GrVkImageLayout>,
69 const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership, GrWrapCacheable,
70 GrIOType);
kkinnunen2e6055b2016-04-22 01:48:29 -070071
Brian Salomon9bc76d92019-01-24 12:18:33 -050072 void removedLastRefOrPendingIO() override;
Brian Salomon614c1a82018-12-19 15:42:06 -050073
74 const GrVkImageView* fTextureView;
75 GrTexture::IdleProc* fIdleProc = nullptr;
76 void* fIdleProcContext = nullptr;
Greg Daniel164a9f02016-02-22 09:56:40 -050077
78 typedef GrTexture INHERITED;
79};
80
81#endif