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

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

Issue 2770943004: cros: Fix browser header wrongly drawn frame image (Closed)
Patch Set: based on suggestions Created 3 years, 9 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
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.h ('k') | no next file » | 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 <cmath> 7 #include <cmath>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 TileImageInt(image, 0, 0, x, y, w, h); 484 TileImageInt(image, 0, 0, x, y, w, h);
485 } 485 }
486 486
487 void Canvas::TileImageInt(const ImageSkia& image, 487 void Canvas::TileImageInt(const ImageSkia& image,
488 int src_x, 488 int src_x,
489 int src_y, 489 int src_y,
490 int dest_x, 490 int dest_x,
491 int dest_y, 491 int dest_y,
492 int w, 492 int w,
493 int h) { 493 int h) {
494 TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h); 494 cc::PaintFlags flags;
495 TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h, &flags);
495 } 496 }
496 497
497 void Canvas::TileImageInt(const ImageSkia& image, 498 void Canvas::TileImageInt(const ImageSkia& image,
499 int src_x,
500 int src_y,
501 int dest_x,
502 int dest_y,
503 int w,
504 int h,
505 cc::PaintFlags* flags) {
506 TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h, flags);
507 }
508
509 void Canvas::TileImageInt(const ImageSkia& image,
498 int src_x, 510 int src_x,
499 int src_y, 511 int src_y,
500 float tile_scale_x, 512 float tile_scale_x,
501 float tile_scale_y, 513 float tile_scale_y,
502 int dest_x, 514 int dest_x,
503 int dest_y, 515 int dest_y,
504 int w, 516 int w,
505 int h) { 517 int h,
518 cc::PaintFlags* flags) {
506 SkRect dest_rect = { SkIntToScalar(dest_x), 519 SkRect dest_rect = { SkIntToScalar(dest_x),
507 SkIntToScalar(dest_y), 520 SkIntToScalar(dest_y),
508 SkIntToScalar(dest_x + w), 521 SkIntToScalar(dest_x + w),
509 SkIntToScalar(dest_y + h) }; 522 SkIntToScalar(dest_y + h) };
510 if (!IntersectsClipRect(dest_rect)) 523 if (!IntersectsClipRect(dest_rect))
511 return; 524 return;
512 525
513 cc::PaintFlags flags; 526 DCHECK(flags);
514 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y, 527 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y,
515 dest_x, dest_y, &flags)) 528 dest_x, dest_y, flags))
516 canvas_->drawRect(dest_rect, flags); 529 canvas_->drawRect(dest_rect, *flags);
517 } 530 }
518 531
519 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, 532 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image,
520 int src_x, 533 int src_x,
521 int src_y, 534 int src_y,
522 float tile_scale_x, 535 float tile_scale_x,
523 float tile_scale_y, 536 float tile_scale_y,
524 int dest_x, 537 int dest_x,
525 int dest_y, 538 int dest_y,
526 cc::PaintFlags* flags) { 539 cc::PaintFlags* flags) {
527 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); 540 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
528 if (image_rep.is_null()) 541 if (image_rep.is_null())
529 return false; 542 return false;
530 543
531 SkMatrix shader_scale; 544 SkMatrix shader_scale;
532 shader_scale.setScale(SkFloatToScalar(tile_scale_x), 545 shader_scale.setScale(SkFloatToScalar(tile_scale_x),
533 SkFloatToScalar(tile_scale_y)); 546 SkFloatToScalar(tile_scale_y));
534 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); 547 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
535 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); 548 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
536 549
537 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, 550 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode,
538 shader_scale)); 551 shader_scale));
539 flags->setBlendMode(SkBlendMode::kSrcOver);
540 return true; 552 return true;
541 } 553 }
542 554
543 void Canvas::Transform(const gfx::Transform& transform) { 555 void Canvas::Transform(const gfx::Transform& transform) {
544 canvas_->concat(transform.matrix()); 556 canvas_->concat(transform.matrix());
545 } 557 }
546 558
547 SkBitmap Canvas::GetBitmap() const { 559 SkBitmap Canvas::GetBitmap() const {
548 DCHECK(bitmap_); 560 DCHECK(bitmap_);
549 SkBitmap bitmap = bitmap_.value(); 561 SkBitmap bitmap = bitmap_.value();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 bitmap_.emplace(); 634 bitmap_.emplace();
623 bitmap_->allocPixels(info); 635 bitmap_->allocPixels(info);
624 // Ensure that the bitmap is zeroed, since the code expects that. 636 // Ensure that the bitmap is zeroed, since the code expects that.
625 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); 637 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize());
626 638
627 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); 639 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value());
628 return &owned_canvas_.value(); 640 return &owned_canvas_.value();
629 } 641 }
630 642
631 } // namespace gfx 643 } // namespace gfx
OLDNEW
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698