| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/gfx/canvas.h" | 5 #include "app/gfx/canvas.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/gfx/font.h" | 9 #include "app/gfx/font.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 void Canvas::ScaleInt(int x, int y) { | 48 void Canvas::ScaleInt(int x, int y) { |
| 49 scale(SkIntToScalar(x), SkIntToScalar(y)); | 49 scale(SkIntToScalar(x), SkIntToScalar(y)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { | 52 void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { |
| 53 SkPaint paint; | 53 SkPaint paint; |
| 54 paint.setColor(color); | 54 paint.setColor(color); |
| 55 paint.setStyle(SkPaint::kFill_Style); | 55 paint.setStyle(SkPaint::kFill_Style); |
| 56 paint.setPorterDuffXfermode(SkPorterDuff::kSrcOver_Mode); | 56 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 57 FillRectInt(x, y, w, h, paint); | 57 FillRectInt(x, y, w, h, paint); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void Canvas::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { | 60 void Canvas::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { |
| 61 SkIRect rc = {x, y, x + w, y + h}; | 61 SkIRect rc = {x, y, x + w, y + h}; |
| 62 drawIRect(rc, paint); | 62 drawIRect(rc, paint); |
| 63 } | 63 } |
| 64 | 64 |
| 65 void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { | 65 void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { |
| 66 DrawRectInt(color, x, y, w, h, SkPorterDuff::kSrcOver_Mode); | 66 DrawRectInt(color, x, y, w, h, SkXfermode::kSrcOver_Mode); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, | 69 void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, |
| 70 SkPorterDuff::Mode mode) { | 70 SkXfermode::Mode mode) { |
| 71 SkPaint paint; | 71 SkPaint paint; |
| 72 paint.setColor(color); | 72 paint.setColor(color); |
| 73 paint.setStyle(SkPaint::kStroke_Style); | 73 paint.setStyle(SkPaint::kStroke_Style); |
| 74 // Set a stroke width of 0, which will put us down the stroke rect path. If | 74 // Set a stroke width of 0, which will put us down the stroke rect path. If |
| 75 // we set a stroke width of 1, for example, this will internally create a | 75 // we set a stroke width of 1, for example, this will internally create a |
| 76 // path and fill it, which causes problems near the edge of the canvas. | 76 // path and fill it, which causes problems near the edge of the canvas. |
| 77 paint.setStrokeWidth(SkIntToScalar(0)); | 77 paint.setStrokeWidth(SkIntToScalar(0)); |
| 78 paint.setPorterDuffXfermode(mode); | 78 paint.setXfermodeMode(mode); |
| 79 | 79 |
| 80 SkIRect rc = {x, y, x + w, y + h}; | 80 SkIRect rc = {x, y, x + w, y + h}; |
| 81 drawIRect(rc, paint); | 81 drawIRect(rc, paint); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { | 84 void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { |
| 85 SkPaint paint; | 85 SkPaint paint; |
| 86 paint.setColor(color); | 86 paint.setColor(color); |
| 87 paint.setStrokeWidth(SkIntToScalar(1)); | 87 paint.setStrokeWidth(SkIntToScalar(1)); |
| 88 drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2), | 88 drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2), |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 int dest_x, int dest_y, int w, int h) { | 229 int dest_x, int dest_y, int w, int h) { |
| 230 if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) | 230 if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) |
| 231 return; | 231 return; |
| 232 | 232 |
| 233 SkPaint paint; | 233 SkPaint paint; |
| 234 | 234 |
| 235 SkShader* shader = SkShader::CreateBitmapShader(bitmap, | 235 SkShader* shader = SkShader::CreateBitmapShader(bitmap, |
| 236 SkShader::kRepeat_TileMode, | 236 SkShader::kRepeat_TileMode, |
| 237 SkShader::kRepeat_TileMode); | 237 SkShader::kRepeat_TileMode); |
| 238 paint.setShader(shader); | 238 paint.setShader(shader); |
| 239 paint.setPorterDuffXfermode(SkPorterDuff::kSrcOver_Mode); | 239 paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); |
| 240 | 240 |
| 241 // CreateBitmapShader returns a Shader with a reference count of one, we | 241 // CreateBitmapShader returns a Shader with a reference count of one, we |
| 242 // need to unref after paint takes ownership of the shader. | 242 // need to unref after paint takes ownership of the shader. |
| 243 shader->unref(); | 243 shader->unref(); |
| 244 save(); | 244 save(); |
| 245 translate(SkIntToScalar(dest_x - src_x), SkIntToScalar(dest_y - src_y)); | 245 translate(SkIntToScalar(dest_x - src_x), SkIntToScalar(dest_y - src_y)); |
| 246 ClipRectInt(src_x, src_y, w, h); | 246 ClipRectInt(src_x, src_y, w, h); |
| 247 drawPaint(paint); | 247 drawPaint(paint); |
| 248 restore(); | 248 restore(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 SkBitmap Canvas::ExtractBitmap() { | 251 SkBitmap Canvas::ExtractBitmap() { |
| 252 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); | 252 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); |
| 253 | 253 |
| 254 // Make a bitmap to return, and a canvas to draw into it. We don't just want | 254 // Make a bitmap to return, and a canvas to draw into it. We don't just want |
| 255 // to call extractSubset or the copy constuctor, since we want an actual copy | 255 // to call extractSubset or the copy constuctor, since we want an actual copy |
| 256 // of the bitmap. | 256 // of the bitmap. |
| 257 SkBitmap result; | 257 SkBitmap result; |
| 258 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | 258 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
| 259 return result; | 259 return result; |
| 260 } | 260 } |
| 261 | 261 |
| 262 } // namespace gfx | 262 } // namespace gfx |
| OLD | NEW |