Fixed textbox color not updating cache, and taking snapshot images for cache instead of storing surfaces
This commit is contained in:
parent
ed3d5f6d51
commit
f72d8c21fa
7 changed files with 27 additions and 19 deletions
|
|
@ -640,8 +640,10 @@ void DrawingProgram::draw(SkCanvas* canvas, const DrawData& drawData) {
|
|||
parallel_loop_all_components([&](auto& c) {
|
||||
c->obj->calculate_draw_transform(drawData);
|
||||
});
|
||||
for(auto& c : components.client_list())
|
||||
for(auto& c : components.client_list()) {
|
||||
c->obj->draw(canvas, drawData);
|
||||
c->obj->drawSetupData.shouldDraw = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(world.main.drawProgCache.disableDrawCache) {
|
||||
|
|
|
|||
|
|
@ -279,8 +279,13 @@ void DrawingProgramCache::refresh_all_draw_cache(const DrawData& drawData) {
|
|||
std::deque<std::shared_ptr<DrawingProgramCacheBVHNode>> nodeFlatList; // We want to render children before parents, so that parents can make use of the cached children
|
||||
traverse_bvh_run_function(drawData.cam.viewingAreaGenerousCollider, [&](std::shared_ptr<DrawingProgramCacheBVHNode> node, const std::vector<CollabListType::ObjectInfoPtr>& comps) {
|
||||
if(node && node->coords.inverseScale <= drawData.cam.c.inverseScale) {
|
||||
if(!node->drawCache)
|
||||
if(!node->drawCache) {
|
||||
nodeFlatList.emplace_front(node);
|
||||
for(auto& nodeChild : node->children) {
|
||||
if(!nodeChild->drawCache)
|
||||
nodeFlatList.emplace_front(nodeChild);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -297,16 +302,17 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptr<DrawingProgra
|
|||
DrawingProgramCacheBVHNode::DrawCacheData drawCache;
|
||||
|
||||
SkImageInfo imgInfo = SkImageInfo::MakeN32Premul(bvhNode->resolution.x(), bvhNode->resolution.y());
|
||||
sk_sp<SkSurface> drawCacheSurface;
|
||||
#ifdef USE_SKIA_BACKEND_GRAPHITE
|
||||
drawCache.surface = SkSurfaces::RenderTarget(drawP.world.main.window.recorder(), imgInfo, skgpu::Mipmapped::kNo, drawP.world.main.window.defaultMSAASurfaceProps);
|
||||
drawCacheSurface = SkSurfaces::RenderTarget(drawP.world.main.window.recorder(), imgInfo, skgpu::Mipmapped::kNo, drawP.world.main.window.defaultMSAASurfaceProps);
|
||||
#elif USE_SKIA_BACKEND_GANESH
|
||||
drawCache.surface = SkSurfaces::RenderTarget(drawP.world.main.window.ctx.get(), skgpu::Budgeted::kNo, imgInfo, drawP.world.main.window.defaultMSAASampleCount, &drawP.world.main.window.defaultMSAASurfaceProps);
|
||||
drawCacheSurface = SkSurfaces::RenderTarget(drawP.world.main.window.ctx.get(), skgpu::Budgeted::kNo, imgInfo, drawP.world.main.window.defaultMSAASampleCount, &drawP.world.main.window.defaultMSAASurfaceProps);
|
||||
#endif
|
||||
|
||||
if(!drawCache.surface)
|
||||
if(!drawCacheSurface)
|
||||
throw std::runtime_error("[DrawingProgramCache::refresh_draw_cache] Could not make cache surface");
|
||||
|
||||
SkCanvas* cacheCanvas = drawCache.surface->getCanvas();
|
||||
SkCanvas* cacheCanvas = drawCacheSurface->getCanvas();
|
||||
|
||||
cacheCanvas->clear(SkColor4f{0, 0, 0, 0});
|
||||
|
||||
|
|
@ -317,6 +323,7 @@ void DrawingProgramCache::refresh_draw_cache(const std::shared_ptr<DrawingProgra
|
|||
cacheDrawData.refresh_draw_optimizing_values();
|
||||
|
||||
draw_components_to_canvas(cacheCanvas, cacheDrawData, &drawCache.lastDrawnComponentPlacement);
|
||||
drawCache.img = drawCacheSurface->makeImageSnapshot()->withDefaultMipmaps();
|
||||
drawCache.lastRenderTime = std::chrono::steady_clock::now();
|
||||
drawCache.attachedCache = this;
|
||||
|
||||
|
|
@ -374,11 +381,10 @@ void DrawingProgramCache::draw_components_to_canvas(SkCanvas* canvas, const Draw
|
|||
|
||||
lastComponentDrawn = std::max(lastComponentDrawn, drawCache.lastDrawnComponentPlacement);
|
||||
|
||||
SkPaint p;
|
||||
p.setBlendMode(SkBlendMode::kSrc);
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setBlendMode(SkBlendMode::kSrc);
|
||||
|
||||
// Note, no mipmaps here. You might need to generate mipmaps in the future (withDefaultMipmaps)
|
||||
canvas->drawImage(drawCache.surface->makeTemporaryImage(), 0, 0, {SkFilterMode::kLinear, SkMipmapMode::kLinear}, &p);
|
||||
canvas->drawImage(drawCache.img, 0, 0, {SkFilterMode::kLinear, SkMipmapMode::kLinear}, &srcPaint);
|
||||
|
||||
canvas->restore();
|
||||
nextCacheToRender++;
|
||||
|
|
@ -396,11 +402,10 @@ void DrawingProgramCache::draw_components_to_canvas(SkCanvas* canvas, const Draw
|
|||
|
||||
lastComponentDrawn = std::max(lastComponentDrawn, drawCache.lastDrawnComponentPlacement);
|
||||
|
||||
SkPaint p;
|
||||
p.setBlendMode(SkBlendMode::kSrc);
|
||||
SkPaint srcPaint;
|
||||
srcPaint.setBlendMode(SkBlendMode::kSrc);
|
||||
|
||||
// Note, no mipmaps here. You might need to generate mipmaps in the future (withDefaultMipmaps)
|
||||
canvas->drawImage(drawCache.surface->makeTemporaryImage(), 0, 0, {SkFilterMode::kLinear, SkMipmapMode::kLinear}, &p);
|
||||
canvas->drawImage(drawCache.img, 0, 0, {SkFilterMode::kLinear, SkMipmapMode::kLinear}, &srcPaint);
|
||||
|
||||
canvas->restore();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class DrawingProgramCacheBVHNode {
|
|||
struct DrawCacheData {
|
||||
uint64_t lastDrawnComponentPlacement;
|
||||
uint64_t firstDrawnComponentPlacement;
|
||||
sk_sp<SkSurface> surface;
|
||||
sk_sp<SkImage> img;
|
||||
std::chrono::steady_clock::time_point lastRenderTime;
|
||||
DrawingProgramCache* attachedCache;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ void TextBoxTool::reset_tool() {
|
|||
}
|
||||
|
||||
bool TextBoxTool::edit_gui(const std::shared_ptr<DrawTextBox>& a) {
|
||||
DrawTextBox::Data oldData = a->d;
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool text");
|
||||
t.gui.text_label_centered("Edit Text");
|
||||
|
|
@ -45,7 +44,9 @@ bool TextBoxTool::edit_gui(const std::shared_ptr<DrawTextBox>& a) {
|
|||
t.gui.text_label("Text Color");
|
||||
});
|
||||
t.gui.pop_id();
|
||||
return a->d != oldData;
|
||||
bool editHappened = a->d != controls.oldData;
|
||||
controls.oldData = a->d;
|
||||
return editHappened;
|
||||
}
|
||||
|
||||
void TextBoxTool::commit_edit_updates(const std::shared_ptr<DrawTextBox>& a, std::any& prevData) {
|
||||
|
|
@ -93,7 +94,6 @@ bool TextBoxTool::edit_update(const std::shared_ptr<DrawTextBox>& a) {
|
|||
mousePointCollection.recalculate_bounds();
|
||||
|
||||
a->textBox.setWidth(std::abs(a->d.p2.x() - a->d.p1.x()));
|
||||
a->create_collider();
|
||||
|
||||
InputManager& input = drawP.world.main.input;
|
||||
auto& textbox = a->textBox;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class TextBoxTool {
|
|||
Vector2f endAt;
|
||||
int drawStage = 0;
|
||||
std::shared_ptr<DrawTextBox> intermediateItem;
|
||||
DrawTextBox::Data oldData;
|
||||
} controls;
|
||||
|
||||
DrawingProgram& drawP;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue