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

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

Issue 8476019: ui/gfx: Convert Canvas::DrawRectInt() to use gfx::Rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: reland - WHAT HERE could have broken media_unittests???? Created 9 years 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_skia.cc ('k') | ui/gfx/render_text.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) 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"
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 const SkColor& text_color, 408 const SkColor& text_color,
409 const SkColor& halo_color_in, 409 const SkColor& halo_color_in,
410 int x, int y, int w, int h, 410 int x, int y, int w, int h,
411 int flags) { 411 int flags) {
412 // Some callers will have semitransparent halo colors, which we don't handle 412 // Some callers will have semitransparent halo colors, which we don't handle
413 // (since the resulting image can have 1-bit transparency only). 413 // (since the resulting image can have 1-bit transparency only).
414 SkColor halo_color = halo_color_in | 0xFF000000; 414 SkColor halo_color = halo_color_in | 0xFF000000;
415 415
416 // Create a temporary buffer filled with the halo color. It must leave room 416 // Create a temporary buffer filled with the halo color. It must leave room
417 // for the 1-pixel border around the text. 417 // for the 1-pixel border around the text.
418 CanvasSkia text_canvas(w + 2, h + 2, true); 418 gfx::Rect rect(gfx::Point(), gfx::Size(w + 2, h + 2));
419 CanvasSkia text_canvas(rect.width(), rect.height(), true);
419 SkPaint bkgnd_paint; 420 SkPaint bkgnd_paint;
420 bkgnd_paint.setColor(halo_color); 421 bkgnd_paint.setColor(halo_color);
421 text_canvas.DrawRectInt(0, 0, w + 2, h + 2, bkgnd_paint); 422 text_canvas.DrawRect(rect, bkgnd_paint);
422 423
423 // Draw the text into the temporary buffer. This will have correct 424 // Draw the text into the temporary buffer. This will have correct
424 // ClearType since the background color is the same as the halo color. 425 // ClearType since the background color is the same as the halo color.
425 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags); 426 text_canvas.DrawStringInt(text, font, text_color, 1, 1, w, h, flags);
426 427
427 // Windows will have cleared the alpha channel for the pixels it drew. Make it 428 // Windows will have cleared the alpha channel for the pixels it drew. Make it
428 // opaque. We have to do this first since pixelShouldGetHalo will check for 429 // opaque. We have to do this first since pixelShouldGetHalo will check for
429 // 0 to see if a pixel has been modified to transparent, and black text that 430 // 0 to see if a pixel has been modified to transparent, and black text that
430 // Windows draw will look transparent to it! 431 // Windows draw will look transparent to it!
431 skia::MakeOpaque(text_canvas.sk_canvas(), 0, 0, w + 2, h + 2); 432 skia::MakeOpaque(text_canvas.sk_canvas(), rect.x(), rect.y(), rect.width(),
433 rect.height());
432 434
433 uint32_t halo_premul = SkPreMultiplyColor(halo_color); 435 uint32_t halo_premul = SkPreMultiplyColor(halo_color);
434 SkBitmap& text_bitmap = const_cast<SkBitmap&>( 436 SkBitmap& text_bitmap = const_cast<SkBitmap&>(
435 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true)); 437 skia::GetTopDevice(*text_canvas.sk_canvas())->accessBitmap(true));
436 for (int cur_y = 0; cur_y < h + 2; cur_y++) { 438 for (int cur_y = 0; cur_y < h + 2; cur_y++) {
437 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y); 439 uint32_t* text_row = text_bitmap.getAddr32(0, cur_y);
438 for (int cur_x = 0; cur_x < w + 2; cur_x++) { 440 for (int cur_x = 0; cur_x < w + 2; cur_x++) {
439 if (text_row[cur_x] == halo_premul) { 441 if (text_row[cur_x] == halo_premul) {
440 // This pixel was not touched by the text routines. See if it borders 442 // This pixel was not touched by the text routines. See if it borders
441 // a touched pixel in any of the 4 directions (not diagonally). 443 // a touched pixel in any of the 4 directions (not diagonally).
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 ClipRect(solid_part); 574 ClipRect(solid_part);
573 DrawStringInt(text, font, color, 575 DrawStringInt(text, font, color,
574 text_rect.x(), text_rect.y(), 576 text_rect.x(), text_rect.y(),
575 text_rect.width(), text_rect.height(), 577 text_rect.width(), text_rect.height(),
576 flags); 578 flags);
577 canvas_->restore(); 579 canvas_->restore();
578 canvas_->restore(); 580 canvas_->restore();
579 } 581 }
580 582
581 } // namespace gfx 583 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas_skia.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698