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 "gfx/canvas.h" | 5 #include "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" |
11 #include "gfx/canvas.h" | |
12 #include "gfx/font.h" | 11 #include "gfx/font.h" |
13 #include "gfx/rect.h" | 12 #include "gfx/rect.h" |
14 #include "third_party/skia/include/core/SkShader.h" | 13 #include "third_party/skia/include/core/SkShader.h" |
15 | 14 |
16 #if defined(OS_WIN) | 15 #if defined(OS_WIN) |
17 #include "gfx/canvas_skia_paint.h" | 16 #include "gfx/canvas_skia_paint.h" |
18 #endif | 17 #endif |
19 | 18 |
20 namespace gfx { | 19 namespace gfx { |
21 | 20 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); | 266 const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); |
268 | 267 |
269 // Make a bitmap to return, and a canvas to draw into it. We don't just want | 268 // Make a bitmap to return, and a canvas to draw into it. We don't just want |
270 // to call extractSubset or the copy constuctor, since we want an actual copy | 269 // to call extractSubset or the copy constuctor, since we want an actual copy |
271 // of the bitmap. | 270 // of the bitmap. |
272 SkBitmap result; | 271 SkBitmap result; |
273 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); | 272 device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
274 return result; | 273 return result; |
275 } | 274 } |
276 | 275 |
| 276 CanvasSkia* CanvasSkia::AsCanvasSkia() { |
| 277 return this; |
| 278 } |
| 279 |
| 280 const CanvasSkia* CanvasSkia::AsCanvasSkia() const { |
| 281 return this; |
| 282 } |
| 283 |
277 // static | 284 // static |
278 int CanvasSkia::DefaultCanvasTextAlignment() { | 285 int CanvasSkia::DefaultCanvasTextAlignment() { |
279 if (!base::i18n::IsRTL()) | 286 if (!base::i18n::IsRTL()) |
280 return gfx::Canvas::TEXT_ALIGN_LEFT; | 287 return gfx::Canvas::TEXT_ALIGN_LEFT; |
281 return gfx::Canvas::TEXT_ALIGN_RIGHT; | 288 return gfx::Canvas::TEXT_ALIGN_RIGHT; |
282 } | 289 } |
283 | 290 |
284 //////////////////////////////////////////////////////////////////////////////// | 291 //////////////////////////////////////////////////////////////////////////////// |
285 // Canvas2, public: | 292 // Canvas, public: |
286 | 293 |
287 Canvas2* Canvas2::CreateCanvas() { | 294 Canvas* Canvas::CreateCanvas() { |
288 return new Canvas; | 295 return new CanvasSkia; |
289 } | 296 } |
290 | 297 |
291 Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) { | 298 Canvas* Canvas::CreateCanvas(int width, int height, bool is_opaque) { |
292 return new Canvas(width, height, is_opaque); | 299 return new CanvasSkia(width, height, is_opaque); |
293 } | 300 } |
294 | 301 |
295 #if defined(OS_WIN) | 302 #if defined(OS_WIN) |
296 // TODO(beng): move to canvas_win.cc, etc. | 303 // TODO(beng): move to canvas_win.cc, etc. |
297 class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint2 { | 304 class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint { |
298 public: | 305 public: |
299 CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} | 306 CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} |
300 | 307 |
301 // Overridden from CanvasPaint2: | 308 // Overridden from CanvasPaint2: |
302 virtual bool IsValid() const { | 309 virtual bool IsValid() const { |
303 return isEmpty(); | 310 return isEmpty(); |
304 } | 311 } |
305 | 312 |
306 virtual gfx::Rect GetInvalidRect() const { | 313 virtual gfx::Rect GetInvalidRect() const { |
307 return gfx::Rect(paintStruct().rcPaint); | 314 return gfx::Rect(paintStruct().rcPaint); |
308 } | 315 } |
309 | 316 |
310 virtual Canvas2* AsCanvas2() { | 317 virtual Canvas* AsCanvas() { |
311 return this; | 318 return this; |
312 } | 319 } |
313 }; | 320 }; |
314 #endif | 321 #endif |
315 | 322 |
316 CanvasPaint2* CanvasPaint2::CreateCanvasPaint(gfx::NativeView view) { | 323 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { |
317 #if defined(OS_WIN) | 324 #if defined(OS_WIN) |
318 return new CanvasPaintWin(view); | 325 return new CanvasPaintWin(view); |
319 #else | 326 #else |
320 return NULL; | 327 return NULL; |
321 #endif | 328 #endif |
322 } | 329 } |
323 | 330 |
324 } // namespace gfx | 331 } // namespace gfx |
OLD | NEW |