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

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

Issue 10701063: Cleanup gfx::Canvas now that 10562027 has landed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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
« no previous file with comments | « ui/gfx/canvas_linux.cc ('k') | ui/gfx/image/canvas_image_source.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "ui/gfx/canvas.h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "ui/base/range/range.h" 10 #include "ui/base/range/range.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 SkColor halo_color_in, 370 SkColor halo_color_in,
371 int x, int y, int w, int h, 371 int x, int y, int w, int h,
372 int flags) { 372 int flags) {
373 // Some callers will have semitransparent halo colors, which we don't handle 373 // Some callers will have semitransparent halo colors, which we don't handle
374 // (since the resulting image can have 1-bit transparency only). 374 // (since the resulting image can have 1-bit transparency only).
375 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF); 375 SkColor halo_color = SkColorSetA(halo_color_in, 0xFF);
376 376
377 // Create a temporary buffer filled with the halo color. It must leave room 377 // Create a temporary buffer filled with the halo color. It must leave room
378 // for the 1-pixel border around the text. 378 // for the 1-pixel border around the text.
379 Size size(w + 2, h + 2); 379 Size size(w + 2, h + 2);
380 Canvas text_canvas(size, true); 380 Canvas text_canvas(size, scale_factor(), true);
381 SkPaint bkgnd_paint; 381 SkPaint bkgnd_paint;
382 bkgnd_paint.setColor(halo_color); 382 bkgnd_paint.setColor(halo_color);
383 text_canvas.DrawRect(gfx::Rect(size), bkgnd_paint); 383 text_canvas.DrawRect(gfx::Rect(size), bkgnd_paint);
384 384
385 // Draw the text into the temporary buffer. This will have correct 385 // Draw the text into the temporary buffer. This will have correct
386 // ClearType since the background color is the same as the halo color. 386 // ClearType since the background color is the same as the halo color.
387 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags); 387 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags);
388 388
389 uint32_t halo_premul = SkPreMultiplyColor(halo_color); 389 uint32_t halo_premul = SkPreMultiplyColor(halo_color);
390 SkBitmap& text_bitmap = const_cast<SkBitmap&>( 390 SkBitmap& text_bitmap = const_cast<SkBitmap&>(
391 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true)); 391 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true));
392 392
393 for (int cur_y = 0; cur_y < h + 2; cur_y++) { 393 for (int cur_y = 0; cur_y < text_bitmap.height(); cur_y++) {
394 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); 394 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y);
395 for (int cur_x = 0; cur_x < w + 2; cur_x++) { 395 for (int cur_x = 0; cur_x < text_bitmap.width(); cur_x++) {
396 if (text_row[cur_x] == halo_premul) { 396 if (text_row[cur_x] == halo_premul) {
397 // This pixel was not touched by the text routines. See if it borders 397 // This pixel was not touched by the text routines. See if it borders
398 // a touched pixel in any of the 4 directions (not diagonally). 398 // a touched pixel in any of the 4 directions (not diagonally).
399 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul)) 399 if (!PixelShouldGetHalo(text_bitmap, cur_x, cur_y, halo_premul))
400 text_row[cur_x] = 0; // Make transparent. 400 text_row[cur_x] = 0; // Make transparent.
401 } else { 401 } else {
402 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque. 402 text_row[cur_x] |= 0xff << SK_A32_SHIFT; // Make opaque.
403 } 403 }
404 } 404 }
405 } 405 }
406 406
407 // Draw the halo bitmap with blur. 407 // Draw the halo bitmap with blur.
408 DrawImageInt(text_bitmap, x - 1, y - 1); 408 gfx::ImageSkia text_image = gfx::ImageSkia(gfx::ImageSkiaRep(text_bitmap,
409 text_canvas.scale_factor()));
410 DrawImageInt(text_image, x - 1, y - 1);
409 } 411 }
410 412
411 void Canvas::DrawFadeTruncatingString( 413 void Canvas::DrawFadeTruncatingString(
412 const string16& text, 414 const string16& text,
413 TruncateFadeMode truncate_mode, 415 TruncateFadeMode truncate_mode,
414 size_t desired_characters_to_truncate_from_head, 416 size_t desired_characters_to_truncate_from_head,
415 const gfx::Font& font, 417 const gfx::Font& font,
416 SkColor color, 418 SkColor color,
417 const gfx::Rect& display_rect) { 419 const gfx::Rect& display_rect) {
418 int flags = NO_ELLIPSIS; 420 int flags = NO_ELLIPSIS;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 rect.set_height(line_height); 475 rect.set_height(line_height);
474 render_text->SetDisplayRect(rect); 476 render_text->SetDisplayRect(rect);
475 477
476 canvas_->save(SkCanvas::kClip_SaveFlag); 478 canvas_->save(SkCanvas::kClip_SaveFlag);
477 ClipRect(display_rect); 479 ClipRect(display_rect);
478 render_text->Draw(this); 480 render_text->Draw(this);
479 canvas_->restore(); 481 canvas_->restore();
480 } 482 }
481 483
482 } // namespace gfx 484 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_linux.cc ('k') | ui/gfx/image/canvas_image_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698