Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Image::isLazyGenerated() to Image::isFullyDecoded(). #138

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions include/tgfx/core/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ class Image {
virtual bool hasMipmaps() const = 0;

/**
* Returns true if Image is backed by an image generator or other services that create their
* pixels on-demand.
* Returns true if the Image and all its children have been fully decoded. A fully decoded Image
* means that its pixels are ready for drawing. On the other hand, if the Image requires decoding
* or rasterization on the CPU side before drawing, it is not yet fully decoded.
*/
virtual bool isLazyGenerated() const;
virtual bool isFullyDecoded() const;

/**
* Returns true if the Image was created from a GPU texture.
Expand Down Expand Up @@ -207,10 +208,10 @@ class Image {
virtual std::shared_ptr<Image> makeTextureImage(Context* context) const;

/**
* Returns a decoded Image from the lazy Image. The returned Image shares the same texture cache
* Returns a fully decoded Image from this Image. The returned Image shares the same GPU cache
* with the original Image and immediately schedules an asynchronous decoding task, which will not
* block the calling thread. Returns the original Image if the Image is not lazy or has a
* corresponding texture cache in the specified context.
* block the calling thread. If the Image is fully decoded or has a corresponding texture cache in
* the specified context, the original Image is returned.
*/
std::shared_ptr<Image> makeDecoded(Context* context = nullptr) const;

Expand Down
4 changes: 2 additions & 2 deletions src/images/GeneratorImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class GeneratorImage : public RasterImage {
return generator->isAlphaOnly();
}

bool isLazyGenerated() const override {
return true;
bool isFullyDecoded() const override {
return false;
}

protected:
Expand Down
6 changes: 3 additions & 3 deletions src/images/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ std::shared_ptr<Image> Image::MakeAdopted(Context* context, const BackendTexture
return TextureImage::MakeFrom(std::move(textureProxy));
}

bool Image::isLazyGenerated() const {
return false;
bool Image::isFullyDecoded() const {
return true;
}

bool Image::isTextureBacked() const {
Expand Down Expand Up @@ -143,7 +143,7 @@ std::shared_ptr<Image> Image::makeTextureImage(Context* context) const {
}

std::shared_ptr<Image> Image::makeDecoded(Context* context) const {
if (!isLazyGenerated()) {
if (isFullyDecoded()) {
return weakThis.lock();
}
auto decoded = onMakeDecoded(context);
Expand Down
4 changes: 2 additions & 2 deletions src/images/NestedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class NestedImage : public Image {
return source->hasMipmaps();
}

bool isLazyGenerated() const override {
return source->isLazyGenerated();
bool isFullyDecoded() const override {
return source->isFullyDecoded();
}

bool isAlphaOnly() const override {
Expand Down
4 changes: 2 additions & 2 deletions src/images/ScaledImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class ScaledImage : public RasterImage {
return source->isAlphaOnly();
}

bool isLazyGenerated() const override {
return source->isLazyGenerated();
bool isFullyDecoded() const override {
return source->isFullyDecoded();
}

std::shared_ptr<Image> makeRasterized(float rasterizationScale = 1.0f) const override;
Expand Down
6 changes: 3 additions & 3 deletions test/src/CanvasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ TGFX_TEST(CanvasTest, image) {
auto canvas = surface->getCanvas();
auto image = MakeImage("resources/apitest/imageReplacement.png");
ASSERT_TRUE(image != nullptr);
EXPECT_TRUE(image->isLazyGenerated());
EXPECT_FALSE(image->isFullyDecoded());
EXPECT_FALSE(image->isTextureBacked());
EXPECT_FALSE(image->hasMipmaps());
auto rotatedImage = image->makeOriented(Orientation::RightTop);
Expand All @@ -687,7 +687,7 @@ TGFX_TEST(CanvasTest, image) {
auto textureImage = image->makeTextureImage(context);
ASSERT_TRUE(textureImage != nullptr);
EXPECT_TRUE(textureImage->isTextureBacked());
EXPECT_FALSE(textureImage->isLazyGenerated());
EXPECT_TRUE(textureImage->isFullyDecoded());
decodedImage = image->makeDecoded(context);
EXPECT_TRUE(decodedImage == image);
textureImage = nullptr;
Expand Down Expand Up @@ -716,7 +716,7 @@ TGFX_TEST(CanvasTest, image) {
decodedImage = image->makeDecoded();
EXPECT_FALSE(decodedImage == image);
ASSERT_TRUE(decodedImage != nullptr);
EXPECT_FALSE(decodedImage->isLazyGenerated());
EXPECT_TRUE(decodedImage->isFullyDecoded());
EXPECT_FALSE(decodedImage->isTextureBacked());
canvas->drawImage(decodedImage, 315, 0);
auto data = Data::MakeFromFile(ProjectPath::Absolute("resources/apitest/rotation.jpg"));
Expand Down
Loading