| 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 <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #include <pango/pango.h> | 9 #include <pango/pango.h> |
| 10 #include <pango/pangocairo.h> | 10 #include <pango/pangocairo.h> |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 font_(font), | 201 font_(font), |
| 202 canvas_(canvas), | 202 canvas_(canvas), |
| 203 cr_(NULL), | 203 cr_(NULL), |
| 204 layout_(NULL), | 204 layout_(NULL), |
| 205 text_x_(bounds.x()), | 205 text_x_(bounds.x()), |
| 206 text_y_(bounds.y()), | 206 text_y_(bounds.y()), |
| 207 text_width_(0), | 207 text_width_(0), |
| 208 text_height_(0) { | 208 text_height_(0) { |
| 209 DCHECK(!bounds_.IsEmpty()); | 209 DCHECK(!bounds_.IsEmpty()); |
| 210 | 210 |
| 211 cr_ = canvas_->beginPlatformPaint(); | 211 cr_ = skia::BeginPlatformPaint(canvas_); |
| 212 layout_ = pango_cairo_create_layout(cr_); | 212 layout_ = pango_cairo_create_layout(cr_); |
| 213 | 213 |
| 214 SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); | 214 SetupPangoLayout(layout_, text, font, bounds_.width(), flags_); |
| 215 | 215 |
| 216 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); | 216 pango_layout_set_height(layout_, bounds_.height() * PANGO_SCALE); |
| 217 | 217 |
| 218 cairo_save(cr_); | 218 cairo_save(cr_); |
| 219 | 219 |
| 220 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); | 220 cairo_rectangle(cr_, clip.x(), clip.y(), clip.width(), clip.height()); |
| 221 cairo_clip(cr_); | 221 cairo_clip(cr_); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 239 double underline_y = | 239 double underline_y = |
| 240 static_cast<double>(text_y_) + text_height_ + | 240 static_cast<double>(text_y_) + text_height_ + |
| 241 platform_font->underline_position(); | 241 platform_font->underline_position(); |
| 242 cairo_set_line_width(cr_, platform_font->underline_thickness()); | 242 cairo_set_line_width(cr_, platform_font->underline_thickness()); |
| 243 cairo_move_to(cr_, text_x_, underline_y); | 243 cairo_move_to(cr_, text_x_, underline_y); |
| 244 cairo_line_to(cr_, text_x_ + text_width_, underline_y); | 244 cairo_line_to(cr_, text_x_ + text_width_, underline_y); |
| 245 cairo_stroke(cr_); | 245 cairo_stroke(cr_); |
| 246 } | 246 } |
| 247 cairo_restore(cr_); | 247 cairo_restore(cr_); |
| 248 | 248 |
| 249 skia::EndPlatformPaint(canvas_); |
| 250 |
| 249 g_object_unref(layout_); | 251 g_object_unref(layout_); |
| 250 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. | 252 // NOTE: BeginPlatformPaint returned its surface, we shouldn't destroy it. |
| 251 } | 253 } |
| 252 | 254 |
| 253 void DrawStringContext::Draw(const SkColor& text_color) { | 255 void DrawStringContext::Draw(const SkColor& text_color) { |
| 254 cairo_set_source_rgba(cr_, | 256 cairo_set_source_rgba(cr_, |
| 255 SkColorGetR(text_color) / 255.0, | 257 SkColorGetR(text_color) / 255.0, |
| 256 SkColorGetG(text_color) / 255.0, | 258 SkColorGetG(text_color) / 255.0, |
| 257 SkColorGetB(text_color) / 255.0, | 259 SkColorGetB(text_color) / 255.0, |
| 258 SkColorGetA(text_color) / 255.0); | 260 SkColorGetA(text_color) / 255.0); |
| 259 cairo_move_to(cr_, text_x_, text_y_); | 261 cairo_move_to(cr_, text_x_, text_y_); |
| 260 pango_cairo_show_layout(cr_, layout_); | 262 pango_cairo_show_layout(cr_, layout_); |
| 261 } | 263 } |
| 262 | 264 |
| 263 void DrawStringContext::DrawWithHalo(const SkColor& text_color, | 265 void DrawStringContext::DrawWithHalo(const SkColor& text_color, |
| 264 const SkColor& halo_color) { | 266 const SkColor& halo_color) { |
| 265 gfx::CanvasSkia text_canvas(bounds_.width() + 2, bounds_.height() + 2, false); | 267 gfx::CanvasSkia text_canvas(bounds_.width() + 2, bounds_.height() + 2, false); |
| 266 text_canvas.FillRectInt(static_cast<SkColor>(0), | 268 text_canvas.FillRectInt(static_cast<SkColor>(0), |
| 267 0, 0, bounds_.width() + 2, bounds_.height() + 2); | 269 0, 0, bounds_.width() + 2, bounds_.height() + 2); |
| 268 | 270 |
| 269 cairo_t* text_cr = text_canvas.beginPlatformPaint(); | 271 { |
| 272 skia::ScopedPlatformPaint scoped_platform_paint(&text_canvas); |
| 273 cairo_t* text_cr = scoped_platform_paint.GetPlatformSurface(); |
| 270 | 274 |
| 271 cairo_move_to(text_cr, 2, 1); | 275 cairo_move_to(text_cr, 2, 1); |
| 272 pango_cairo_layout_path(text_cr, layout_); | 276 pango_cairo_layout_path(text_cr, layout_); |
| 273 | 277 |
| 274 cairo_set_source_rgba(text_cr, | 278 cairo_set_source_rgba(text_cr, |
| 275 SkColorGetR(halo_color) / 255.0, | 279 SkColorGetR(halo_color) / 255.0, |
| 276 SkColorGetG(halo_color) / 255.0, | 280 SkColorGetG(halo_color) / 255.0, |
| 277 SkColorGetB(halo_color) / 255.0, | 281 SkColorGetB(halo_color) / 255.0, |
| 278 SkColorGetA(halo_color) / 255.0); | 282 SkColorGetA(halo_color) / 255.0); |
| 279 cairo_set_line_width(text_cr, 2.0); | 283 cairo_set_line_width(text_cr, 2.0); |
| 280 cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND); | 284 cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND); |
| 281 cairo_stroke_preserve(text_cr); | 285 cairo_stroke_preserve(text_cr); |
| 282 | 286 |
| 283 cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); | 287 cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); |
| 284 cairo_set_source_rgba(text_cr, | 288 cairo_set_source_rgba(text_cr, |
| 285 SkColorGetR(text_color) / 255.0, | 289 SkColorGetR(text_color) / 255.0, |
| 286 SkColorGetG(text_color) / 255.0, | 290 SkColorGetG(text_color) / 255.0, |
| 287 SkColorGetB(text_color) / 255.0, | 291 SkColorGetB(text_color) / 255.0, |
| 288 SkColorGetA(text_color) / 255.0); | 292 SkColorGetA(text_color) / 255.0); |
| 289 cairo_fill(text_cr); | 293 cairo_fill(text_cr); |
| 290 | 294 } |
| 291 text_canvas.endPlatformPaint(); | |
| 292 | 295 |
| 293 const SkBitmap& text_bitmap = const_cast<SkBitmap&>( | 296 const SkBitmap& text_bitmap = const_cast<SkBitmap&>( |
| 294 text_canvas.getTopPlatformDevice().accessBitmap(false)); | 297 skia::GetTopDevice(&text_canvas)->accessBitmap(false)); |
| 295 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); | 298 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); |
| 296 } | 299 } |
| 297 | 300 |
| 298 } // namespace | 301 } // namespace |
| 299 | 302 |
| 300 namespace gfx { | 303 namespace gfx { |
| 301 | 304 |
| 302 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) | 305 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) |
| 303 : skia::PlatformCanvas(width, height, is_opaque) { | 306 : skia::PlatformCanvas(width, height, is_opaque) { |
| 304 } | 307 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 DrawStringContext context(this, text, font, bounds, bounds, flags); | 375 DrawStringContext context(this, text, font, bounds, bounds, flags); |
| 373 context.Draw(color); | 376 context.Draw(color); |
| 374 } | 377 } |
| 375 | 378 |
| 376 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { | 379 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { |
| 377 if (!pixbuf) { | 380 if (!pixbuf) { |
| 378 NOTREACHED(); | 381 NOTREACHED(); |
| 379 return; | 382 return; |
| 380 } | 383 } |
| 381 | 384 |
| 382 cairo_t* cr = beginPlatformPaint(); | 385 skia::ScopedPlatformPaint scoped_platform_paint(this); |
| 386 cairo_t* cr = scoped_platform_paint.GetPlatformSurface(); |
| 383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); | 387 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); |
| 384 cairo_paint(cr); | 388 cairo_paint(cr); |
| 385 } | 389 } |
| 386 | 390 |
| 387 ui::TextureID CanvasSkia::GetTextureID() { | 391 ui::TextureID CanvasSkia::GetTextureID() { |
| 388 // TODO(wjmaclean) | 392 // TODO(wjmaclean) |
| 389 return 0; | 393 return 0; |
| 390 } | 394 } |
| 391 | 395 |
| 392 } // namespace gfx | 396 } // namespace gfx |
| OLD | NEW |