Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Side by Side Diff: ui/gfx/canvas_skia_linux.cc

Issue 7019013: Removal of dependencies on PlatformDevice classes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Addressing comments. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 18 matching lines...) Expand all
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 g_object_unref(layout_); 249 g_object_unref(layout_);
250 // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. 250 // NOTE: BeginPlatformPaint returned its surface, we shouldn't destroy it.
251 } 251 }
252 252
253 void DrawStringContext::Draw(const SkColor& text_color) { 253 void DrawStringContext::Draw(const SkColor& text_color) {
254 cairo_set_source_rgba(cr_, 254 cairo_set_source_rgba(cr_,
255 SkColorGetR(text_color) / 255.0, 255 SkColorGetR(text_color) / 255.0,
256 SkColorGetG(text_color) / 255.0, 256 SkColorGetG(text_color) / 255.0,
257 SkColorGetB(text_color) / 255.0, 257 SkColorGetB(text_color) / 255.0,
258 SkColorGetA(text_color) / 255.0); 258 SkColorGetA(text_color) / 255.0);
259 cairo_move_to(cr_, text_x_, text_y_); 259 cairo_move_to(cr_, text_x_, text_y_);
260 pango_cairo_show_layout(cr_, layout_); 260 pango_cairo_show_layout(cr_, layout_);
261 } 261 }
262 262
263 void DrawStringContext::DrawWithHalo(const SkColor& text_color, 263 void DrawStringContext::DrawWithHalo(const SkColor& text_color,
264 const SkColor& halo_color) { 264 const SkColor& halo_color) {
265 gfx::CanvasSkia text_canvas(bounds_.width() + 2, bounds_.height() + 2, false); 265 gfx::CanvasSkia text_canvas(bounds_.width() + 2, bounds_.height() + 2, false);
266 text_canvas.FillRectInt(static_cast<SkColor>(0), 266 text_canvas.FillRectInt(static_cast<SkColor>(0),
267 0, 0, bounds_.width() + 2, bounds_.height() + 2); 267 0, 0, bounds_.width() + 2, bounds_.height() + 2);
268 268
269 cairo_t* text_cr = text_canvas.beginPlatformPaint(); 269 cairo_t* text_cr = skia::BeginPlatformPaint(&text_canvas);
270 270
271 cairo_move_to(text_cr, 2, 1); 271 cairo_move_to(text_cr, 2, 1);
272 pango_cairo_layout_path(text_cr, layout_); 272 pango_cairo_layout_path(text_cr, layout_);
273 273
274 cairo_set_source_rgba(text_cr, 274 cairo_set_source_rgba(text_cr,
275 SkColorGetR(halo_color) / 255.0, 275 SkColorGetR(halo_color) / 255.0,
276 SkColorGetG(halo_color) / 255.0, 276 SkColorGetG(halo_color) / 255.0,
277 SkColorGetB(halo_color) / 255.0, 277 SkColorGetB(halo_color) / 255.0,
278 SkColorGetA(halo_color) / 255.0); 278 SkColorGetA(halo_color) / 255.0);
279 cairo_set_line_width(text_cr, 2.0); 279 cairo_set_line_width(text_cr, 2.0);
280 cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND); 280 cairo_set_line_join(text_cr, CAIRO_LINE_JOIN_ROUND);
281 cairo_stroke_preserve(text_cr); 281 cairo_stroke_preserve(text_cr);
282 282
283 cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE); 283 cairo_set_operator(text_cr, CAIRO_OPERATOR_SOURCE);
284 cairo_set_source_rgba(text_cr, 284 cairo_set_source_rgba(text_cr,
285 SkColorGetR(text_color) / 255.0, 285 SkColorGetR(text_color) / 255.0,
286 SkColorGetG(text_color) / 255.0, 286 SkColorGetG(text_color) / 255.0,
287 SkColorGetB(text_color) / 255.0, 287 SkColorGetB(text_color) / 255.0,
288 SkColorGetA(text_color) / 255.0); 288 SkColorGetA(text_color) / 255.0);
289 cairo_fill(text_cr); 289 cairo_fill(text_cr);
290 290
291 text_canvas.endPlatformPaint(); 291 skia::EndPlatformPaint(&text_canvas);
292 292
293 const SkBitmap& text_bitmap = const_cast<SkBitmap&>( 293 const SkBitmap& text_bitmap = const_cast<SkBitmap&>(
294 text_canvas.getTopPlatformDevice().accessBitmap(false)); 294 text_canvas.getTopDevice().accessBitmap(false));
295 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1); 295 canvas_->DrawBitmapInt(text_bitmap, text_x_ - 1, text_y_ - 1);
296 } 296 }
297 297
298 } // namespace 298 } // namespace
299 299
300 namespace gfx { 300 namespace gfx {
301 301
302 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) 302 CanvasSkia::CanvasSkia(int width, int height, bool is_opaque)
303 : skia::PlatformCanvas(width, height, is_opaque) { 303 : skia::PlatformCanvas(width, height, is_opaque) {
304 } 304 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 DrawStringContext context(this, text, font, bounds, bounds, flags); 372 DrawStringContext context(this, text, font, bounds, bounds, flags);
373 context.Draw(color); 373 context.Draw(color);
374 } 374 }
375 375
376 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { 376 void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) {
377 if (!pixbuf) { 377 if (!pixbuf) {
378 NOTREACHED(); 378 NOTREACHED();
379 return; 379 return;
380 } 380 }
381 381
382 cairo_t* cr = beginPlatformPaint(); 382 cairo_t* cr = skia::BeginPlatformPaint(this);
383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y); 383 gdk_cairo_set_source_pixbuf(cr, pixbuf, x, y);
384 cairo_paint(cr); 384 cairo_paint(cr);
385 } 385 }
386 386
387 ui::TextureID CanvasSkia::GetTextureID() { 387 ui::TextureID CanvasSkia::GetTextureID() {
388 // TODO(wjmaclean) 388 // TODO(wjmaclean)
389 return 0; 389 return 0;
390 } 390 }
391 391
392 } // namespace gfx 392 } // namespace gfx
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698