Skip to content

Commit

Permalink
Update tgfx to remove SurfaceOptions and use RenderFlags instead. (#2539
Browse files Browse the repository at this point in the history
)
  • Loading branch information
domchen authored Oct 21, 2024
1 parent 90899f5 commit a25261a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"url": "${PAG_GROUP}/tgfx.git",
"commit": "9d6b7464dd22e3a0aa9aa22e0a789cbfed1fed73",
"commit": "57dea46bc27c4815af6fcb14d47eb5faa9cfe360",
"dir": "third_party/tgfx"
},
{
Expand Down
6 changes: 3 additions & 3 deletions src/rendering/caches/RenderCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ void RenderCache::beginFrame() {
}

void RenderCache::attachToContext(tgfx::Context* current, bool forDrawing) {
if (deviceID > 0 && deviceID != current->device()->uniqueID()) {
if (contextID > 0 && contextID != current->uniqueID()) {
// Context 改变需要清理内部所有缓存,这里用 uniqueID
// 而不用指针比较,是因为指针析构后再创建可能会地址重合。
releaseAll();
}
context = current;
context->setCacheLimit(MAX_GRAPHICS_MEMORY);
deviceID = context->device()->uniqueID();
contextID = context->uniqueID();
isDrawingFrame = forDrawing;
if (!isDrawingFrame) {
return;
Expand Down Expand Up @@ -199,7 +199,7 @@ void RenderCache::releaseAll() {
motionBlurFilter = nullptr;
delete transform3DFilter;
transform3DFilter = nullptr;
deviceID = 0;
contextID = 0;
}

void RenderCache::detachFromContext() {
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/caches/RenderCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class RenderCache : public Performance {
private:
ID _uniqueID = 0;
PAGStage* stage = nullptr;
uint32_t deviceID = 0;
uint32_t contextID = 0;
tgfx::Context* context = nullptr;
std::queue<std::chrono::steady_clock::time_point> timestamps = {};
bool isDrawingFrame = false;
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/graphics/Canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ tgfx::Surface* Canvas::getSurface() const {
return canvas->getSurface();
}

const tgfx::SurfaceOptions* Canvas::surfaceOptions() const {
uint32_t Canvas::renderFlags() const {
auto surface = canvas->getSurface();
return surface ? surface->options() : nullptr;
return surface ? surface->renderFlags() : 0;
}

void Canvas::save() {
Expand Down
4 changes: 2 additions & 2 deletions src/rendering/graphics/Canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#pragma once

#include "tgfx/core/Canvas.h"
#include "tgfx/core/SurfaceOptions.h"
#include "tgfx/core/RenderFlags.h"

namespace pag {
class RenderCache;
Expand All @@ -39,7 +39,7 @@ class Canvas {

tgfx::Surface* getSurface() const;

const tgfx::SurfaceOptions* surfaceOptions() const;
uint32_t renderFlags() const;

void save();

Expand Down
12 changes: 6 additions & 6 deletions src/rendering/graphics/Picture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class ImageProxyPicture : public Picture {
canvas->drawImage(std::move(image));
return;
}
auto options = canvas->surfaceOptions();
if (options && !options->cacheDisabled()) {
auto renderFlags = canvas->renderFlags();
if (!(renderFlags & tgfx::RenderFlags::DisableCache)) {
auto snapshot = cache->getSnapshot(this);
if (snapshot) {
canvas->drawImage(snapshot->getImage(), snapshot->getMatrix());
Expand Down Expand Up @@ -168,8 +168,8 @@ class SnapshotPicture : public Picture {
}

void draw(Canvas* canvas) const override {
auto options = canvas->surfaceOptions();
if (options && options->cacheDisabled()) {
auto renderFlags = canvas->renderFlags();
if (renderFlags & tgfx::RenderFlags::DisableCache) {
graphic->draw(canvas);
return;
}
Expand All @@ -192,9 +192,9 @@ class SnapshotPicture : public Picture {
graphic->measureBounds(&bounds);
auto width = static_cast<int>(ceilf(bounds.width() * scaleFactor));
auto height = static_cast<int>(ceilf(bounds.height() * scaleFactor));
tgfx::SurfaceOptions options(tgfx::RenderFlags::DisableCache);
auto renderFlags = tgfx::RenderFlags::DisableCache;
auto surface =
tgfx::Surface::Make(cache->getContext(), width, height, false, 1, mipmapped, &options);
tgfx::Surface::Make(cache->getContext(), width, height, false, 1, mipmapped, renderFlags);
if (surface == nullptr) {
return nullptr;
}
Expand Down

0 comments on commit a25261a

Please sign in to comment.