2019-01-10 17:09:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkPromiseImageTexture_DEFINED
|
|
|
|
#define SkPromiseImageTexture_DEFINED
|
|
|
|
|
|
|
|
#include "../private/GrResourceKey.h"
|
|
|
|
#include "GrBackendSurface.h"
|
2019-01-11 21:03:19 +00:00
|
|
|
#include "SkRefCnt.h"
|
2019-01-10 17:09:52 +00:00
|
|
|
|
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
/**
|
|
|
|
* This type is used to fulfill textures for PromiseImages. Once an instance is returned from a
|
|
|
|
* PromiseImageTextureFulfillProc it must remain valid until the corresponding
|
|
|
|
* PromiseImageTextureReleaseProc is called. For performance reasons it is recommended that the
|
|
|
|
* the client reuse a single PromiseImageTexture every time a given texture is returned by
|
|
|
|
* the PromiseImageTextureFulfillProc rather than recreating PromiseImageTextures representing
|
|
|
|
* the same underlying backend API texture.
|
|
|
|
*/
|
2019-01-11 21:03:19 +00:00
|
|
|
class SK_API SkPromiseImageTexture : public SkNVRefCnt<SkPromiseImageTexture> {
|
2019-01-10 17:09:52 +00:00
|
|
|
public:
|
2019-01-11 21:03:19 +00:00
|
|
|
SkPromiseImageTexture() = delete;
|
2019-01-10 17:09:52 +00:00
|
|
|
SkPromiseImageTexture(const SkPromiseImageTexture&) = delete;
|
2019-01-11 21:03:19 +00:00
|
|
|
SkPromiseImageTexture(SkPromiseImageTexture&&) = delete;
|
2019-01-10 17:09:52 +00:00
|
|
|
~SkPromiseImageTexture();
|
|
|
|
SkPromiseImageTexture& operator=(const SkPromiseImageTexture&) = delete;
|
2019-01-11 21:03:19 +00:00
|
|
|
SkPromiseImageTexture& operator=(SkPromiseImageTexture&&) = delete;
|
|
|
|
|
|
|
|
static sk_sp<SkPromiseImageTexture> Make(const GrBackendTexture& backendTexture) {
|
|
|
|
if (!backendTexture.isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return sk_sp<SkPromiseImageTexture>(new SkPromiseImageTexture(backendTexture));
|
|
|
|
}
|
|
|
|
|
2019-01-10 17:09:52 +00:00
|
|
|
const GrBackendTexture& backendTexture() const { return fBackendTexture; }
|
|
|
|
|
|
|
|
void addKeyToInvalidate(uint32_t contextID, const GrUniqueKey& key);
|
|
|
|
uint32_t uniqueID() const { return fUniqueID; }
|
|
|
|
|
|
|
|
#if GR_TEST_UTILS
|
|
|
|
SkTArray<GrUniqueKey> testingOnly_uniqueKeysToInvalidate() const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
private:
|
2019-01-11 21:03:19 +00:00
|
|
|
explicit SkPromiseImageTexture(const GrBackendTexture& backendTexture);
|
|
|
|
|
2019-01-10 17:09:52 +00:00
|
|
|
SkSTArray<1, GrUniqueKeyInvalidatedMessage> fMessages;
|
|
|
|
GrBackendTexture fBackendTexture;
|
|
|
|
uint32_t fUniqueID = SK_InvalidUniqueID;
|
|
|
|
static std::atomic<uint32_t> gUniqueID;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|