Skip to content

Commit

Permalink
Add the expired() method to the ImageBuffer class.
Browse files Browse the repository at this point in the history
  • Loading branch information
domchen committed Mar 23, 2023
1 parent e1aa2c9 commit f3eba48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tgfx/include/tgfx/core/ImageBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class Texture;

/**
* ImageBuffer describes a two-dimensional array of pixels and is optimized for creating textures.
* ImageBuffer is immutable and safe across threads.
* ImageBuffer is immutable and safe across threads. The content of an ImageBuffer never changes,
* but some ImageBuffers may have a limited lifetime and cannot create textures after they expire.
* For example, the ImageBuffers generated from an ImageReader. In other cases, ImageBuffers usually
* only expire if explicitly stated by the creator.
*/
class ImageBuffer {
public:
Expand Down Expand Up @@ -92,6 +95,14 @@ class ImageBuffer {
*/
virtual bool isAlphaOnly() const = 0;

/**
* Returns true if the ImageBuffer is expired, which means it cannot create any new textures.
* However, you can still safely access all of its properties across threads.
*/
virtual bool expired() const {
return false;
}

protected:
ImageBuffer() = default;

Expand Down
4 changes: 4 additions & 0 deletions tgfx/src/platform/ImageReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ImageReaderBuffer : public ImageBuffer {
return false;
}

bool expired() const override {
return contentVersion < imageReader->textureVersion;
}

protected:
std::shared_ptr<Texture> onMakeTexture(Context* context, bool mipMapped) const override {
return imageReader->readTexture(contentVersion, context, mipMapped);
Expand Down

0 comments on commit f3eba48

Please sign in to comment.