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 GrVkTexture_DEFINED 9 #define GrVkTexture_DEFINED 10 11 #include "GrTexture.h" 12 #include "GrVkImage.h" 13 #include "vk/GrVkTypes.h" 14 15 class GrVkGpu; 16 class GrVkImageView; 17 struct GrVkImageInfo; 18 19 class GrVkTexture : public GrTexture, public virtual GrVkImage { 20 public: 21 static sk_sp<GrVkTexture> MakeNewTexture(GrVkGpu*, 22 SkBudgeted budgeted, 23 const GrSurfaceDesc&, 24 const GrVkImage::ImageDesc&, 25 GrMipMapsStatus); 26 27 static sk_sp<GrVkTexture> MakeWrappedTexture(GrVkGpu*, const GrSurfaceDesc&, GrWrapOwnership, 28 GrWrapCacheable, GrIOType, const GrVkImageInfo&, 29 sk_sp<GrVkImageLayout>); 30 31 ~GrVkTexture() override; 32 33 GrBackendTexture getBackendTexture() const override; 34 backendFormat()35 GrBackendFormat backendFormat() const override { return this->getBackendFormat(); } 36 textureParamsModified()37 void textureParamsModified() override {} 38 39 const GrVkImageView* textureView(); 40 41 void addIdleProc(sk_sp<GrRefCntedCallback>) override; removeIdleProc()42 void removeIdleProc() { fIdleCallback.reset(); } 43 44 protected: 45 GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp<GrVkImageLayout>, 46 const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership); 47 48 GrVkGpu* getVkGpu() const; 49 50 void onAbandon() override; 51 void onRelease() override; 52 onStealBackendTexture(GrBackendTexture *,SkImage::BackendTextureReleaseProc *)53 bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) override { 54 return false; 55 } 56 57 void willRemoveLastRefOrPendingIO() override; 58 59 private: 60 GrVkTexture(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&, const GrVkImageInfo&, 61 sk_sp<GrVkImageLayout> layout, const GrVkImageView* imageView, 62 GrMipMapsStatus); 63 GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp<GrVkImageLayout>, 64 const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership, GrWrapCacheable, 65 GrIOType); 66 67 // In Vulkan we call the release proc after we are finished with the underlying 68 // GrVkImage::Resource object (which occurs after the GPU has finished all work on it). onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper)69 void onSetRelease(sk_sp<GrRefCntedCallback> releaseHelper) override { 70 // Forward the release proc on to GrVkImage 71 this->setResourceRelease(std::move(releaseHelper)); 72 } 73 74 const GrVkImageView* fTextureView; 75 76 typedef GrTexture INHERITED; 77 }; 78 79 #endif 80