Fix images drawn with the NineImagePainter class in high DPI.
commit54bc2461dd6c6272029a7c51c6f6cdcf9e1f3ec0
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Tue, 6 May 2014 05:10:58 +0000 (6 05:10 +0000)
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>
Tue, 6 May 2014 05:10:58 +0000 (6 05:10 +0000)
treee570f3cae71b4943edb22379eba488aec67a99cd
parentfa130eb07a7e76bb17e6cbcd57f0920c25a38bbd
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

Review URL: https://codereview.chromium.org/262773010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268429 0039d316-1c4b-4281-b951-d872f2087c98
ui/gfx/canvas.cc
ui/gfx/canvas.h
ui/gfx/nine_image_painter.cc
ui/gfx/skia_util.cc
ui/gfx/skia_util.h