| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 for (int u = 0; u < col_pixels; u++) { | 133 for (int u = 0; u < col_pixels; u++) { |
| 134 if ((u % 2 + i % 2) % 2 != 0) { | 134 if ((u % 2 + i % 2) % 2 != 0) { |
| 135 dot[i * row_pixels + u] = color; | 135 dot[i * row_pixels + u] = color; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Make a shader for the bitmap with an origin of the box we'll draw. This | 141 // Make a shader for the bitmap with an origin of the box we'll draw. This |
| 142 // shader is refcounted and will have an initial refcount of 1. | 142 // shader is refcounted and will have an initial refcount of 1. |
| 143 SkShader* shader = SkShader::CreateBitmapShader( | 143 skia::RefPtr<SkShader> shader = SkShader::CreateBitmapShader( |
| 144 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 144 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
| 145 // Assign the shader to the paint & release our reference. The paint will | 145 // Assign the shader to the paint & release our reference. The paint will |
| 146 // now own the shader and the shader will be destroyed when the paint goes | 146 // now own the shader and the shader will be destroyed when the paint goes |
| 147 // out of scope. | 147 // out of scope. |
| 148 SkPaint paint; | 148 SkPaint paint; |
| 149 paint.setShader(shader); | 149 paint.setShader(shader.get()); |
| 150 shader->unref(); | |
| 151 | 150 |
| 152 DrawRect(gfx::Rect(rect.x(), rect.y(), rect.width(), 1), paint); | 151 DrawRect(gfx::Rect(rect.x(), rect.y(), rect.width(), 1), paint); |
| 153 DrawRect(gfx::Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), | 152 DrawRect(gfx::Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), |
| 154 paint); | 153 paint); |
| 155 DrawRect(gfx::Rect(rect.x(), rect.y(), 1, rect.height()), paint); | 154 DrawRect(gfx::Rect(rect.x(), rect.y(), 1, rect.height()), paint); |
| 156 DrawRect(gfx::Rect(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()), | 155 DrawRect(gfx::Rect(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()), |
| 157 paint); | 156 paint); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void Canvas::Save() { | 159 void Canvas::Save() { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // Make a bitmap shader that contains the bitmap we want to draw. This is | 365 // Make a bitmap shader that contains the bitmap we want to draw. This is |
| 367 // basically what SkCanvas.drawBitmap does internally, but it gives us | 366 // basically what SkCanvas.drawBitmap does internally, but it gives us |
| 368 // more control over quality and will use the mipmap in the source image if | 367 // more control over quality and will use the mipmap in the source image if |
| 369 // it has one, whereas drawBitmap won't. | 368 // it has one, whereas drawBitmap won't. |
| 370 SkMatrix shader_scale; | 369 SkMatrix shader_scale; |
| 371 shader_scale.setScale(SkFloatToScalar(user_scale_x), | 370 shader_scale.setScale(SkFloatToScalar(user_scale_x), |
| 372 SkFloatToScalar(user_scale_y)); | 371 SkFloatToScalar(user_scale_y)); |
| 373 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); | 372 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
| 374 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); | 373 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
| 375 | 374 |
| 376 SkShader* shader = gfx::CreateImageRepShader(image_rep, | 375 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
| 377 SkShader::kRepeat_TileMode, | 376 image_rep, |
| 378 shader_scale); | 377 SkShader::kRepeat_TileMode, |
| 378 shader_scale); |
| 379 | 379 |
| 380 // Set up our paint to use the shader & release our reference (now just owned | 380 // Set up our paint to use the shader & release our reference (now just owned |
| 381 // by the paint). | 381 // by the paint). |
| 382 SkPaint p(paint); | 382 SkPaint p(paint); |
| 383 p.setFilterBitmap(filter); | 383 p.setFilterBitmap(filter); |
| 384 p.setShader(shader); | 384 p.setShader(shader.get()); |
| 385 shader->unref(); | |
| 386 | 385 |
| 387 // The rect will be filled by the bitmap. | 386 // The rect will be filled by the bitmap. |
| 388 canvas_->drawRect(dest_rect, p); | 387 canvas_->drawRect(dest_rect, p); |
| 389 } | 388 } |
| 390 | 389 |
| 391 void Canvas::DrawImageInPath(const gfx::ImageSkia& image, | 390 void Canvas::DrawImageInPath(const gfx::ImageSkia& image, |
| 392 int x, | 391 int x, |
| 393 int y, | 392 int y, |
| 394 const SkPath& path, | 393 const SkPath& path, |
| 395 const SkPaint& paint) { | 394 const SkPaint& paint) { |
| 396 const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image); | 395 const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image); |
| 397 if (image_rep.is_null()) | 396 if (image_rep.is_null()) |
| 398 return; | 397 return; |
| 399 | 398 |
| 400 SkMatrix matrix; | 399 SkMatrix matrix; |
| 401 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); | 400 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); |
| 402 SkShader* shader = gfx::CreateImageRepShader(image_rep, | 401 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
| 403 SkShader::kRepeat_TileMode, matrix); | 402 image_rep, |
| 403 SkShader::kRepeat_TileMode, |
| 404 matrix); |
| 404 | 405 |
| 405 SkPaint p(paint); | 406 SkPaint p(paint); |
| 406 p.setShader(shader); | 407 p.setShader(shader.get()); |
| 407 shader->unref(); | |
| 408 canvas_->drawPath(path, p); | 408 canvas_->drawPath(path, p); |
| 409 } | 409 } |
| 410 | 410 |
| 411 void Canvas::DrawStringInt(const string16& text, | 411 void Canvas::DrawStringInt(const string16& text, |
| 412 const gfx::Font& font, | 412 const gfx::Font& font, |
| 413 SkColor color, | 413 SkColor color, |
| 414 int x, int y, int w, int h) { | 414 int x, int y, int w, int h) { |
| 415 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); | 415 DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); |
| 416 } | 416 } |
| 417 | 417 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 tile_scale_x, tile_scale_y); | 458 tile_scale_x, tile_scale_y); |
| 459 if (image_rep.is_null()) | 459 if (image_rep.is_null()) |
| 460 return; | 460 return; |
| 461 | 461 |
| 462 SkMatrix shader_scale; | 462 SkMatrix shader_scale; |
| 463 shader_scale.setScale(SkFloatToScalar(tile_scale_x), | 463 shader_scale.setScale(SkFloatToScalar(tile_scale_x), |
| 464 SkFloatToScalar(tile_scale_y)); | 464 SkFloatToScalar(tile_scale_y)); |
| 465 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); | 465 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
| 466 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); | 466 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
| 467 | 467 |
| 468 SkShader* shader = gfx::CreateImageRepShader(image_rep, | 468 skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
| 469 SkShader::kRepeat_TileMode, | 469 image_rep, |
| 470 shader_scale); | 470 SkShader::kRepeat_TileMode, |
| 471 shader_scale); |
| 471 | 472 |
| 472 SkPaint paint; | 473 SkPaint paint; |
| 473 paint.setShader(shader); | 474 paint.setShader(shader.get()); |
| 474 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 475 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 475 shader->unref(); | |
| 476 | 476 |
| 477 SkRect dest_rect = { SkIntToScalar(dest_x), | 477 SkRect dest_rect = { SkIntToScalar(dest_x), |
| 478 SkIntToScalar(dest_y), | 478 SkIntToScalar(dest_y), |
| 479 SkIntToScalar(dest_x + w), | 479 SkIntToScalar(dest_x + w), |
| 480 SkIntToScalar(dest_y + h) }; | 480 SkIntToScalar(dest_y + h) }; |
| 481 canvas_->drawRect(dest_rect, paint); | 481 canvas_->drawRect(dest_rect, paint); |
| 482 } | 482 } |
| 483 | 483 |
| 484 gfx::NativeDrawingContext Canvas::BeginPlatformPaint() { | 484 gfx::NativeDrawingContext Canvas::BeginPlatformPaint() { |
| 485 return skia::BeginPlatformPaint(canvas_); | 485 return skia::BeginPlatformPaint(canvas_); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 | 532 |
| 533 float bitmap_scale = image_rep.GetScale(); | 533 float bitmap_scale = image_rep.GetScale(); |
| 534 if (scale_x < bitmap_scale || scale_y < bitmap_scale) | 534 if (scale_x < bitmap_scale || scale_y < bitmap_scale) |
| 535 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); | 535 const_cast<SkBitmap&>(image_rep.sk_bitmap()).buildMipMap(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 return image_rep; | 538 return image_rep; |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace gfx | 541 } // namespace gfx |
| OLD | NEW |