SkPromiseImageTexture.h 2.1 KB

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