| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_skia.h" | 5 #include "ui/gfx/canvas_skia.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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 FillRect(color, rect, SkXfermode::kSrcOver_Mode); | 126 FillRect(color, rect, SkXfermode::kSrcOver_Mode); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void CanvasSkia::FillRect(const SkColor& color, | 129 void CanvasSkia::FillRect(const SkColor& color, |
| 130 const gfx::Rect& rect, | 130 const gfx::Rect& rect, |
| 131 SkXfermode::Mode mode) { | 131 SkXfermode::Mode mode) { |
| 132 SkPaint paint; | 132 SkPaint paint; |
| 133 paint.setColor(color); | 133 paint.setColor(color); |
| 134 paint.setStyle(SkPaint::kFill_Style); | 134 paint.setStyle(SkPaint::kFill_Style); |
| 135 paint.setXfermodeMode(mode); | 135 paint.setXfermodeMode(mode); |
| 136 DrawRectInt(rect.x(), rect.y(), rect.width(), rect.height(), paint); | 136 DrawRect(rect, paint); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void CanvasSkia::FillRect(const gfx::Brush* brush, const gfx::Rect& rect) { | 139 void CanvasSkia::FillRect(const gfx::Brush* brush, const gfx::Rect& rect) { |
| 140 const SkiaShader* shader = static_cast<const SkiaShader*>(brush); | 140 const SkiaShader* shader = static_cast<const SkiaShader*>(brush); |
| 141 SkPaint paint; | 141 SkPaint paint; |
| 142 paint.setShader(shader->shader()); | 142 paint.setShader(shader->shader()); |
| 143 // TODO(beng): set shader transform to match canvas transform. | 143 // TODO(beng): set shader transform to match canvas transform. |
| 144 DrawRectInt(rect.x(), rect.y(), rect.width(), rect.height(), paint); | 144 DrawRect(rect, paint); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { | 147 void CanvasSkia::DrawRect(const gfx::Rect& rect, const SkPaint& paint) { |
| 148 DrawRectInt(color, x, y, w, h, SkXfermode::kSrcOver_Mode); | 148 canvas_->drawIRect(RectToSkIRect(rect), paint); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void CanvasSkia::DrawRectInt(const SkColor& color, | 151 void CanvasSkia::DrawRect(const gfx::Rect& rect, const SkColor& color) { |
| 152 int x, int y, int w, int h, | 152 DrawRect(rect, color, SkXfermode::kSrcOver_Mode); |
| 153 SkXfermode::Mode mode) { | 153 } |
| 154 |
| 155 void CanvasSkia::DrawRect(const gfx::Rect& rect, |
| 156 const SkColor& color, |
| 157 SkXfermode::Mode mode) { |
| 154 SkPaint paint; | 158 SkPaint paint; |
| 155 paint.setColor(color); | 159 paint.setColor(color); |
| 156 paint.setStyle(SkPaint::kStroke_Style); | 160 paint.setStyle(SkPaint::kStroke_Style); |
| 157 // Set a stroke width of 0, which will put us down the stroke rect path. If | 161 // Set a stroke width of 0, which will put us down the stroke rect path. If |
| 158 // we set a stroke width of 1, for example, this will internally create a | 162 // we set a stroke width of 1, for example, this will internally create a |
| 159 // path and fill it, which causes problems near the edge of the canvas. | 163 // path and fill it, which causes problems near the edge of the canvas. |
| 160 paint.setStrokeWidth(SkIntToScalar(0)); | 164 paint.setStrokeWidth(SkIntToScalar(0)); |
| 161 paint.setXfermodeMode(mode); | 165 paint.setXfermodeMode(mode); |
| 162 | 166 |
| 163 DrawRectInt(x, y, w, h, paint); | 167 DrawRect(rect, paint); |
| 164 } | |
| 165 | |
| 166 void CanvasSkia::DrawRectInt(int x, int y, int w, int h, const SkPaint& paint) { | |
| 167 SkIRect rc = { x, y, x + w, y + h }; | |
| 168 canvas_->drawIRect(rc, paint); | |
| 169 } | 168 } |
| 170 | 169 |
| 171 void CanvasSkia::DrawLineInt(const SkColor& color, | 170 void CanvasSkia::DrawLineInt(const SkColor& color, |
| 172 int x1, int y1, | 171 int x1, int y1, |
| 173 int x2, int y2) { | 172 int x2, int y2) { |
| 174 SkPaint paint; | 173 SkPaint paint; |
| 175 paint.setColor(color); | 174 paint.setColor(color); |
| 176 paint.setStrokeWidth(SkIntToScalar(1)); | 175 paint.setStrokeWidth(SkIntToScalar(1)); |
| 177 canvas_->drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2), | 176 canvas_->drawLine(SkIntToScalar(x1), SkIntToScalar(y1), SkIntToScalar(x2), |
| 178 SkIntToScalar(y2), paint); | 177 SkIntToScalar(y2), paint); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 207 // shader is refcounted and will have an initial refcount of 1. | 206 // shader is refcounted and will have an initial refcount of 1. |
| 208 SkShader* shader = SkShader::CreateBitmapShader( | 207 SkShader* shader = SkShader::CreateBitmapShader( |
| 209 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); | 208 *dots, SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode); |
| 210 // Assign the shader to the paint & release our reference. The paint will | 209 // Assign the shader to the paint & release our reference. The paint will |
| 211 // now own the shader and the shader will be destroyed when the paint goes | 210 // now own the shader and the shader will be destroyed when the paint goes |
| 212 // out of scope. | 211 // out of scope. |
| 213 SkPaint paint; | 212 SkPaint paint; |
| 214 paint.setShader(shader); | 213 paint.setShader(shader); |
| 215 shader->unref(); | 214 shader->unref(); |
| 216 | 215 |
| 217 DrawRectInt(rect.x(), rect.y(), rect.width(), 1, paint); | 216 DrawRect(gfx::Rect(rect.x(), rect.y(), rect.width(), 1), paint); |
| 218 DrawRectInt(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1, paint); | 217 DrawRect(gfx::Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), |
| 219 DrawRectInt(rect.x(), rect.y(), 1, rect.height(), paint); | 218 paint); |
| 220 DrawRectInt(rect.x() + rect.width() - 1, rect.y(), 1, rect.height(), paint); | 219 DrawRect(gfx::Rect(rect.x(), rect.y(), 1, rect.height()), paint); |
| 220 DrawRect(gfx::Rect(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()), |
| 221 paint); |
| 221 } | 222 } |
| 222 | 223 |
| 223 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { | 224 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { |
| 224 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); | 225 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, | 228 void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, |
| 228 int x, int y, | 229 int x, int y, |
| 229 const SkPaint& paint) { | 230 const SkPaint& paint) { |
| 230 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); | 231 canvas_->drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 | 413 |
| 413 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { | 414 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { |
| 414 #if defined(OS_WIN) && !defined(USE_AURA) | 415 #if defined(OS_WIN) && !defined(USE_AURA) |
| 415 return new CanvasPaintWin(view); | 416 return new CanvasPaintWin(view); |
| 416 #else | 417 #else |
| 417 return NULL; | 418 return NULL; |
| 418 #endif | 419 #endif |
| 419 } | 420 } |
| 420 | 421 |
| 421 } // namespace gfx | 422 } // namespace gfx |
| OLD | NEW |