diff options
author | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 23:27:04 +0000 |
---|---|---|
committer | pkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-25 23:27:04 +0000 |
commit | 2a3115ee449130d77908d22db405f47a8f3a025f (patch) | |
tree | 1d3331f9719f408cc8786b0ecec34ed9542f9894 /ui/gfx/canvas.cc | |
parent | f126deb615adb20b6b267bff338ab3da5b10c25a (diff) | |
download | chromium_src-2a3115ee449130d77908d22db405f47a8f3a025f.zip chromium_src-2a3115ee449130d77908d22db405f47a8f3a025f.tar.gz chromium_src-2a3115ee449130d77908d22db405f47a8f3a025f.tar.bz2 |
native_theme_base/android had copied and pasted versions of DrawBitmapInt and TileImageInt. Made these two files use the version inside of Canvas.
Also fixed hidden bug in ::DrawTiledImage where src_x and src_y translates are applied after the tile scale instead of before.
This bug is hidden as neither native_theme_base/android called DrawTiledImage with src_x/src_y != 0.
Bug=124566
Test=Webkit fast/* layout tests produce no image diffs
Review URL: https://chromiumcodereview.appspot.com/10452035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/canvas.cc')
-rw-r--r-- | ui/gfx/canvas.cc | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc index 0baed6e5..6dd9d98 100644 --- a/ui/gfx/canvas.cc +++ b/ui/gfx/canvas.cc @@ -338,7 +338,8 @@ void Canvas::DrawBitmapInt(const gfx::ImageSkia& image, SkFloatToScalar(-src_y * bitmap_scale)); shader_scale.postTranslate(SkFloatToScalar(dest_x * bitmap_scale), SkFloatToScalar(dest_y * bitmap_scale)); - shader_scale.postScale(1.0f / bitmap_scale, 1.0f / bitmap_scale); + shader_scale.postScale(SkFloatToScalar(1.0f / bitmap_scale), + SkFloatToScalar(1.0f / bitmap_scale)); shader->setLocalMatrix(shader_scale); // Set up our paint to use the shader & release our reference (now just owned @@ -388,11 +389,21 @@ void Canvas::TileImageInt(const gfx::ImageSkia& image, void Canvas::TileImageInt(const gfx::ImageSkia& image, int src_x, int src_y, int dest_x, int dest_y, int w, int h) { + TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h); +} + +void Canvas::TileImageInt(const gfx::ImageSkia& image, + int src_x, int src_y, + float tile_scale_x, float tile_scale_y, + int dest_x, int dest_y, int w, int h) { if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) return; float bitmap_scale; - const SkBitmap& bitmap = GetBitmapToPaint(image, &bitmap_scale); + const SkBitmap& bitmap = GetBitmapToPaint(image, + tile_scale_x, + tile_scale_y, + &bitmap_scale); if (bitmap.isNull()) return; @@ -401,20 +412,26 @@ void Canvas::TileImageInt(const gfx::ImageSkia& image, SkShader* shader = SkShader::CreateBitmapShader(bitmap, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); + + SkMatrix shader_scale; + shader_scale.setScale(SkFloatToScalar(tile_scale_x), + SkFloatToScalar(tile_scale_y)); + shader_scale.preTranslate(SkFloatToScalar(-src_x * bitmap_scale), + SkFloatToScalar(-src_y * bitmap_scale)); + shader_scale.postTranslate(SkFloatToScalar(dest_x * bitmap_scale), + SkFloatToScalar(dest_y * bitmap_scale)); + shader_scale.postScale(SkFloatToScalar(1.0f / bitmap_scale), + SkFloatToScalar(1.0f / bitmap_scale)); + shader->setLocalMatrix(shader_scale); + paint.setShader(shader); paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); - // CreateBitmapShader returns a Shader with a reference count of one, we - // need to unref after paint takes ownership of the shader. - shader->unref(); - canvas_->save(); - canvas_->translate(SkIntToScalar(dest_x - src_x), - SkIntToScalar(dest_y - src_y)); - ClipRect(gfx::Rect(src_x, src_y, w, h)); - canvas_->scale(SkFloatToScalar(1.0f / bitmap_scale), - SkFloatToScalar(1.0f / bitmap_scale)); - canvas_->drawPaint(paint); - canvas_->restore(); + SkRect dest_rect = { SkIntToScalar(dest_x), + SkIntToScalar(dest_y), + SkIntToScalar(dest_x + w), + SkIntToScalar(dest_y + h) }; + canvas_->drawRect(dest_rect, paint); } gfx::NativeDrawingContext Canvas::BeginPlatformPaint() { |