| 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" | 
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" | 11 #include "third_party/skia/include/effects/SkGradientShader.h" | 
| 12 #include "ui/gfx/brush.h" | 12 #include "ui/gfx/brush.h" | 
| 13 #include "ui/gfx/font.h" | 13 #include "ui/gfx/font.h" | 
| 14 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" | 
|  | 15 #include "ui/gfx/skia_util.h" | 
| 15 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" | 
| 16 | 17 | 
| 17 #if defined(OS_WIN) | 18 #if defined(OS_WIN) | 
| 18 #include "ui/gfx/canvas_skia_paint.h" | 19 #include "ui/gfx/canvas_skia_paint.h" | 
| 19 #endif | 20 #endif | 
| 20 | 21 | 
| 21 namespace { | 22 namespace { | 
| 22 | 23 | 
| 23 // A platform wrapper for a Skia shader that makes sure the underlying | 24 // A platform wrapper for a Skia shader that makes sure the underlying | 
| 24 // SkShader object is unref'ed when this object is destroyed. | 25 // SkShader object is unref'ed when this object is destroyed. | 
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 102              SkIntToScalar(layer_bounds.y()), | 103              SkIntToScalar(layer_bounds.y()), | 
| 103              SkIntToScalar(layer_bounds.right()), | 104              SkIntToScalar(layer_bounds.right()), | 
| 104              SkIntToScalar(layer_bounds.bottom())); | 105              SkIntToScalar(layer_bounds.bottom())); | 
| 105   canvas_->saveLayerAlpha(&bounds, alpha); | 106   canvas_->saveLayerAlpha(&bounds, alpha); | 
| 106 } | 107 } | 
| 107 | 108 | 
| 108 void CanvasSkia::Restore() { | 109 void CanvasSkia::Restore() { | 
| 109   canvas_->restore(); | 110   canvas_->restore(); | 
| 110 } | 111 } | 
| 111 | 112 | 
| 112 bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) { | 113 bool CanvasSkia::ClipRectInt(const gfx::Rect& rect) { | 
| 113   SkRect new_clip; | 114   return canvas_->clipRect(gfx::RectToSkRect(rect)); | 
| 114   new_clip.set(SkIntToScalar(x), SkIntToScalar(y), |  | 
| 115                SkIntToScalar(x + w), SkIntToScalar(y + h)); |  | 
| 116   return canvas_->clipRect(new_clip); |  | 
| 117 } | 115 } | 
| 118 | 116 | 
| 119 void CanvasSkia::TranslateInt(int x, int y) { | 117 void CanvasSkia::TranslateInt(int x, int y) { | 
| 120   canvas_->translate(SkIntToScalar(x), SkIntToScalar(y)); | 118   canvas_->translate(SkIntToScalar(x), SkIntToScalar(y)); | 
| 121 } | 119 } | 
| 122 | 120 | 
| 123 void CanvasSkia::ScaleInt(int x, int y) { | 121 void CanvasSkia::ScaleInt(int x, int y) { | 
| 124   canvas_->scale(SkIntToScalar(x), SkIntToScalar(y)); | 122   canvas_->scale(SkIntToScalar(x), SkIntToScalar(y)); | 
| 125 } | 123 } | 
| 126 | 124 | 
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 329                                                   SkShader::kRepeat_TileMode); | 327                                                   SkShader::kRepeat_TileMode); | 
| 330   paint.setShader(shader); | 328   paint.setShader(shader); | 
| 331   paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 329   paint.setXfermodeMode(SkXfermode::kSrcOver_Mode); | 
| 332 | 330 | 
| 333   // CreateBitmapShader returns a Shader with a reference count of one, we | 331   // CreateBitmapShader returns a Shader with a reference count of one, we | 
| 334   // need to unref after paint takes ownership of the shader. | 332   // need to unref after paint takes ownership of the shader. | 
| 335   shader->unref(); | 333   shader->unref(); | 
| 336   canvas_->save(); | 334   canvas_->save(); | 
| 337   canvas_->translate(SkIntToScalar(dest_x - src_x), | 335   canvas_->translate(SkIntToScalar(dest_x - src_x), | 
| 338                      SkIntToScalar(dest_y - src_y)); | 336                      SkIntToScalar(dest_y - src_y)); | 
| 339   ClipRectInt(src_x, src_y, w, h); | 337   ClipRectInt(gfx::Rect(src_x, src_y, w, h)); | 
| 340   canvas_->drawPaint(paint); | 338   canvas_->drawPaint(paint); | 
| 341   canvas_->restore(); | 339   canvas_->restore(); | 
| 342 } | 340 } | 
| 343 | 341 | 
| 344 gfx::NativeDrawingContext CanvasSkia::BeginPlatformPaint() { | 342 gfx::NativeDrawingContext CanvasSkia::BeginPlatformPaint() { | 
| 345   return skia::BeginPlatformPaint(canvas_); | 343   return skia::BeginPlatformPaint(canvas_); | 
| 346 } | 344 } | 
| 347 | 345 | 
| 348 void CanvasSkia::EndPlatformPaint() { | 346 void CanvasSkia::EndPlatformPaint() { | 
| 349   skia::EndPlatformPaint(canvas_); | 347   skia::EndPlatformPaint(canvas_); | 
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 415 | 413 | 
| 416 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { | 414 CanvasPaint* CanvasPaint::CreateCanvasPaint(gfx::NativeView view) { | 
| 417 #if defined(OS_WIN) && !defined(USE_AURA) | 415 #if defined(OS_WIN) && !defined(USE_AURA) | 
| 418   return new CanvasPaintWin(view); | 416   return new CanvasPaintWin(view); | 
| 419 #else | 417 #else | 
| 420   return NULL; | 418   return NULL; | 
| 421 #endif | 419 #endif | 
| 422 } | 420 } | 
| 423 | 421 | 
| 424 }  // namespace gfx | 422 }  // namespace gfx | 
| OLD | NEW | 
|---|