1 /* 2 * Copyright 2017 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 SkPromiseImageTexture_DEFINED 9 #define SkPromiseImageTexture_DEFINED 10 11 #include "../private/GrResourceKey.h" 12 #include "GrBackendSurface.h" 13 #include "SkRefCnt.h" 14 15 #if SK_SUPPORT_GPU 16 /** 17 * This type is used to fulfill textures for PromiseImages. Once an instance is returned from a 18 * PromiseImageTextureFulfillProc it must remain valid until the corresponding 19 * PromiseImageTextureReleaseProc is called. For performance reasons it is recommended that the 20 * the client reuse a single PromiseImageTexture every time a given texture is returned by 21 * the PromiseImageTextureFulfillProc rather than recreating PromiseImageTextures representing 22 * the same underlying backend API texture. 23 */ 24 class SK_API SkPromiseImageTexture : public SkNVRefCnt<SkPromiseImageTexture> { 25 public: 26 SkPromiseImageTexture() = delete; 27 SkPromiseImageTexture(const SkPromiseImageTexture&) = delete; 28 SkPromiseImageTexture(SkPromiseImageTexture&&) = delete; 29 ~SkPromiseImageTexture(); 30 SkPromiseImageTexture& operator=(const SkPromiseImageTexture&) = delete; 31 SkPromiseImageTexture& operator=(SkPromiseImageTexture&&) = delete; 32 Make(const GrBackendTexture & backendTexture)33 static sk_sp<SkPromiseImageTexture> Make(const GrBackendTexture& backendTexture) { 34 if (!backendTexture.isValid()) { 35 return nullptr; 36 } 37 return sk_sp<SkPromiseImageTexture>(new SkPromiseImageTexture(backendTexture)); 38 } 39 backendTexture()40 const GrBackendTexture& backendTexture() const { return fBackendTexture; } 41 42 void addKeyToInvalidate(uint32_t contextID, const GrUniqueKey& key); uniqueID()43 uint32_t uniqueID() const { return fUniqueID; } 44 45 #if GR_TEST_UTILS 46 SkTArray<GrUniqueKey> testingOnly_uniqueKeysToInvalidate() const; 47 #endif 48 49 private: 50 explicit SkPromiseImageTexture(const GrBackendTexture& backendTexture); 51 52 SkSTArray<1, GrUniqueKeyInvalidatedMessage> fMessages; 53 GrBackendTexture fBackendTexture; 54 uint32_t fUniqueID = SK_InvalidUniqueID; 55 static std::atomic<uint32_t> gUniqueID; 56 }; 57 #endif 58 59 #endif 60