Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Issue 262773010: Fix images drawn with the NineImagePainter class in high DPI. (Closed)

Created:
6 years, 7 months ago by ananta
Modified:
6 years, 7 months ago
Reviewers:
oshima, sky
CC:
chromium-reviews
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Visibility:
Public.

Description

Fix images drawn with the NineImagePainter class in high DPI. This class is used for drawing custom buttons/scrollbars, etc. On Windows high DPI for fractional scale factors like 1.25/1.5, etc these images appear distorted due to pixel loss occuring while drawing. The loss happens due to the following reasons. 1. The class uses two different flavors of the Canvas::DrawImageInt function to draw. One flavor is invoked via a local helper called Fill and the other one is used to draw some images. The latter causes painting problems for fractional scales as it rounds differently via the skia helper SkScalarRoundToInt which internally ends up adding 0.5 to the value being ceiled and ceils it at times. 2. The NineImagePainter class uses ImageSkiaStorage.width and height to get the DIP width and height respectively. These methods divide the pixel width/height by the scale factor and return the floored results. This causes pixel loss. E.g. pixel width/height 8 and scale favtor 1.5. These methods return 5 (5.33 rounded to 5). This causes pixel loss eventually. 3. The bounds of the rect being painted to which is passed into the paint function contain width/height values which when scaled cause rounding problems. Fixes for the above issues are as below:- 1. Added a new function DrawImageIntInPixel to the gfx::Canvas class. This function ensures that the underlying SkCanvas does not scale. It translates the destination rectangle to ensure that the image is displayed at the desired location. 2. Changed the drawing code in the NineImagePainter class to pass in pixel locations/width/height etc for drawing. BUG=367543 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=268429

Patch Set 1 #

Patch Set 2 : Removed newlines #

Patch Set 3 : NineImagePainter draws using raw pixels #

Total comments: 12

Patch Set 4 : Code review comments #

Patch Set 5 : Renamed variables #

Total comments: 5

Patch Set 6 : Code review comments #

Patch Set 7 : Code review comments #

Patch Set 8 : Rebased to tip #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+231 lines, -82 lines) Patch
M ui/gfx/canvas.h View 1 2 2 chunks +34 lines, -0 lines 0 comments Download
M ui/gfx/canvas.cc View 1 2 3 4 5 6 4 chunks +132 lines, -58 lines 1 comment Download
M ui/gfx/nine_image_painter.cc View 1 2 3 4 chunks +45 lines, -19 lines 0 comments Download
M ui/gfx/skia_util.h View 1 2 1 chunk +7 lines, -0 lines 0 comments Download
M ui/gfx/skia_util.cc View 1 2 3 4 5 2 chunks +13 lines, -5 lines 0 comments Download

Messages

Total messages: 15 (0 generated)
ananta
6 years, 7 months ago (2014-05-02 02:16:08 UTC) #1
ananta
6 years, 7 months ago (2014-05-02 02:16:16 UTC) #2
sky
Since you're trying to align images, which are pixel based, I think this code would ...
6 years, 7 months ago (2014-05-02 14:36:32 UTC) #3
ananta
Updated the NineImagePainter class to pass in raw pixel values for drawing as per discussion. ...
6 years, 7 months ago (2014-05-03 03:49:36 UTC) #4
sky
https://codereview.chromium.org/262773010/diff/30001/ui/gfx/canvas.cc File ui/gfx/canvas.cc (right): https://codereview.chromium.org/262773010/diff/30001/ui/gfx/canvas.cc#newcode396 ui/gfx/canvas.cc:396: // 1. Translate the destination rectangle with using the ...
6 years, 7 months ago (2014-05-05 14:08:16 UTC) #5
ananta
https://codereview.chromium.org/262773010/diff/30001/ui/gfx/canvas.cc File ui/gfx/canvas.cc (right): https://codereview.chromium.org/262773010/diff/30001/ui/gfx/canvas.cc#newcode396 ui/gfx/canvas.cc:396: // 1. Translate the destination rectangle with using the ...
6 years, 7 months ago (2014-05-05 18:53:27 UTC) #6
sky
https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc File ui/gfx/canvas.cc (right): https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc#newcode422 ui/gfx/canvas.cc:422: Scale(1.0f, 1.0f); Is this needed? Haven't you effectively reset ...
6 years, 7 months ago (2014-05-05 20:51:13 UTC) #7
ananta
https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc File ui/gfx/canvas.cc (right): https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc#newcode422 ui/gfx/canvas.cc:422: Scale(1.0f, 1.0f); On 2014/05/05 20:51:14, sky wrote: > Is ...
6 years, 7 months ago (2014-05-05 21:36:20 UTC) #8
sky
https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc File ui/gfx/canvas.cc (right): https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc#newcode440 ui/gfx/canvas.cc:440: image_scale_ = image_scale; On 2014/05/05 21:36:20, ananta wrote: > ...
6 years, 7 months ago (2014-05-06 00:24:10 UTC) #9
ananta
On 2014/05/06 00:24:10, sky wrote: > https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc > File ui/gfx/canvas.cc (right): > > https://codereview.chromium.org/262773010/diff/70001/ui/gfx/canvas.cc#newcode440 > ...
6 years, 7 months ago (2014-05-06 00:27:55 UTC) #10
sky
LGTM
6 years, 7 months ago (2014-05-06 00:31:27 UTC) #11
ananta
The CQ bit was checked by ananta@chromium.org
6 years, 7 months ago (2014-05-06 01:20:35 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/ananta@chromium.org/262773010/130001
6 years, 7 months ago (2014-05-06 01:22:14 UTC) #13
commit-bot: I haz the power
Change committed as 268429
6 years, 7 months ago (2014-05-06 05:11:01 UTC) #14
oshima
6 years, 7 months ago (2014-05-06 06:44:01 UTC) #15
Message was sent while issue was closed.
drive by:

https://codereview.chromium.org/262773010/diff/130001/ui/gfx/canvas.cc
File ui/gfx/canvas.cc (right):

https://codereview.chromium.org/262773010/diff/130001/ui/gfx/canvas.cc#newcod...
ui/gfx/canvas.cc:413: matrix.mapRect(&destination_rect, destination_rect);
This doesn't seem to work if the canvas is rotated, say 45 degree. Am I wrong?

Powered by Google App Engine
This is Rietveld 408576698