From 84b44a36ea04f3130f173c4ff2f9534b4a6b9659 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 11 Apr 2019 22:54:47 -0300 Subject: [PATCH] Improve ui::Theme::drawSlices() performance using os::Surface::drawSurfaceNine() --- laf | 2 +- src/ui/graphics.cpp | 14 +++++++++ src/ui/graphics.h | 8 +++++ src/ui/theme.cpp | 74 ++++----------------------------------------- 4 files changed, 29 insertions(+), 69 deletions(-) diff --git a/laf b/laf index 6586d4000..05592ba7b 160000 --- a/laf +++ b/laf @@ -1 +1 @@ -Subproject commit 6586d40005077d5a4ede8375d7f4c8ed0f44b3fe +Subproject commit 05592ba7b36b0eb22d50b4ae5c5b160a0794b05d diff --git a/src/ui/graphics.cpp b/src/ui/graphics.cpp index 43c90f8d7..00bcecdce 100644 --- a/src/ui/graphics.cpp +++ b/src/ui/graphics.cpp @@ -253,6 +253,20 @@ void Graphics::drawColoredRgbaSurface(os::Surface* surface, gfx::Color color, gfx::Clip(m_dx+dstx, m_dy+dsty, srcx, srcy, w, h)); } +void Graphics::drawSurfaceNine(os::Surface* surface, + const gfx::Rect& src, + const gfx::Rect& center, + const gfx::Rect& dst, + const ui::Paint* paint) +{ + gfx::Rect displacedDst(m_dx+dst.x, m_dy+dst.y, dst.w, dst.h); + dirty(displacedDst); + + os::SurfaceLock lockSrc(surface); + os::SurfaceLock lockDst(m_surface); + m_surface->drawSurfaceNine(surface, src, center, displacedDst, paint); +} + void Graphics::blit(os::Surface* srcSurface, int srcx, int srcy, int dstx, int dsty, int w, int h) { dirty(gfx::Rect(m_dx+dstx, m_dy+dsty, w, h)); diff --git a/src/ui/graphics.h b/src/ui/graphics.h index acff32272..3cd2b1f68 100644 --- a/src/ui/graphics.h +++ b/src/ui/graphics.h @@ -1,4 +1,5 @@ // Aseprite UI Library +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -15,6 +16,7 @@ #include "gfx/point.h" #include "gfx/rect.h" #include "gfx/size.h" +#include "os/paint.h" #include @@ -29,6 +31,7 @@ namespace os { } namespace ui { + using os::Paint; // Class to render a widget in the screen. class Graphics { @@ -83,6 +86,11 @@ namespace ui { const gfx::Rect& dstRect); void drawColoredRgbaSurface(os::Surface* surface, gfx::Color color, int x, int y); void drawColoredRgbaSurface(os::Surface* surface, gfx::Color color, int srcx, int srcy, int dstx, int dsty, int w, int h); + void drawSurfaceNine(os::Surface* surface, + const gfx::Rect& src, + const gfx::Rect& center, + const gfx::Rect& dst, + const Paint* paint = nullptr); void blit(os::Surface* src, int srcx, int srcy, int dstx, int dsty, int w, int h); diff --git a/src/ui/theme.cpp b/src/ui/theme.cpp index f1897c16c..de89bbfea 100644 --- a/src/ui/theme.cpp +++ b/src/ui/theme.cpp @@ -1,4 +1,5 @@ // Aseprite UI Library +// Copyright (C) 2019 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This file is released under the terms of the MIT license. @@ -695,74 +696,11 @@ void Theme::drawSlices(Graphics* g, os::Surface* sheet, const gfx::Color color, const bool drawCenter) { - const int w1 = slices.x; - const int h1 = slices.y; - const int w2 = slices.w; - const int h2 = slices.h; - const int w3 = sprite.w-w1-w2; - const int h3 = sprite.h-h1-h2; - const int x2 = rc.x2()-w3; - const int y2 = rc.y2()-h3; - auto draw = getDrawSurfaceFunction(g, sheet, color); - - // Top - int x = rc.x; - int y = rc.y; - draw(sprite.x, sprite.y, - x, y, w1, h1); - { - IntersectClip clip(g, gfx::Rect(rc.x+w1, rc.y, rc.w-w1-w3, h1)); - if (clip) { - for (x+=w1; xdrawSurfaceNine(sheet, sprite, slices, rc, &paint); } // static