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

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

Issue 2770943004: cros: Fix browser header wrongly drawn frame image (Closed)
Patch Set: feedback 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
« no previous file with comments | « 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 int h) { 483 int h) {
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 }
496
497 void Canvas::TileImageInt(const ImageSkia& image,
498 int src_x,
499 int src_y,
500 float tile_scale_x,
501 float tile_scale_y,
502 int dest_x,
503 int dest_y,
504 int w,
505 int h) {
506 SkRect dest_rect = { SkIntToScalar(dest_x), 495 SkRect dest_rect = { SkIntToScalar(dest_x),
507 SkIntToScalar(dest_y), 496 SkIntToScalar(dest_y),
508 SkIntToScalar(dest_x + w), 497 SkIntToScalar(dest_x + w),
509 SkIntToScalar(dest_y + h) }; 498 SkIntToScalar(dest_y + h) };
510 if (!IntersectsClipRect(dest_rect)) 499 if (!IntersectsClipRect(dest_rect))
511 return; 500 return;
512 501
513 cc::PaintFlags flags; 502 cc::PaintFlags paint_flags;
514 if (InitPaintFlagsForTiling(image, src_x, src_y, tile_scale_x, tile_scale_y, 503 if (!flags)
515 dest_x, dest_y, &flags)) 504 flags = &paint_flags;
516 canvas_->drawRect(dest_rect, flags); 505
506 if (InitPaintFlagsForTiling(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y,
507 flags))
508 canvas_->drawRect(dest_rect, *flags);
517 } 509 }
518 510
519 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image, 511 bool Canvas::InitPaintFlagsForTiling(const ImageSkia& image,
520 int src_x, 512 int src_x,
521 int src_y, 513 int src_y,
522 float tile_scale_x, 514 float tile_scale_x,
danakj 2017/03/28 14:34:37 These tile_scales are never anything but 1.f anymo
Qiang(Joe) Xu 2017/03/28 17:11:15 seems https://cs.chromium.org/chromium/src/chrome/
danakj 2017/03/28 17:49:41 Oh.. I assumed it is a private method, kinda surpr
523 float tile_scale_y, 515 float tile_scale_y,
524 int dest_x, 516 int dest_x,
525 int dest_y, 517 int dest_y,
526 cc::PaintFlags* flags) { 518 cc::PaintFlags* flags) {
527 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); 519 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
528 if (image_rep.is_null()) 520 if (image_rep.is_null())
529 return false; 521 return false;
530 522
531 SkMatrix shader_scale; 523 SkMatrix shader_scale;
532 shader_scale.setScale(SkFloatToScalar(tile_scale_x), 524 shader_scale.setScale(SkFloatToScalar(tile_scale_x),
533 SkFloatToScalar(tile_scale_y)); 525 SkFloatToScalar(tile_scale_y));
534 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); 526 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
535 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); 527 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
536 528
537 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, 529 flags->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode,
538 shader_scale)); 530 shader_scale));
539 flags->setBlendMode(SkBlendMode::kSrcOver);
540 return true; 531 return true;
541 } 532 }
542 533
543 void Canvas::Transform(const gfx::Transform& transform) { 534 void Canvas::Transform(const gfx::Transform& transform) {
544 canvas_->concat(transform.matrix()); 535 canvas_->concat(transform.matrix());
545 } 536 }
546 537
547 SkBitmap Canvas::GetBitmap() const { 538 SkBitmap Canvas::GetBitmap() const {
548 DCHECK(bitmap_); 539 DCHECK(bitmap_);
549 SkBitmap bitmap = bitmap_.value(); 540 SkBitmap bitmap = bitmap_.value();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 bitmap_.emplace(); 613 bitmap_.emplace();
623 bitmap_->allocPixels(info); 614 bitmap_->allocPixels(info);
624 // Ensure that the bitmap is zeroed, since the code expects that. 615 // Ensure that the bitmap is zeroed, since the code expects that.
625 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize()); 616 memset(bitmap_->getPixels(), 0, bitmap_->getSafeSize());
626 617
627 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value()); 618 owned_canvas_ = cc::SkiaPaintCanvas(bitmap_.value());
628 return &owned_canvas_.value(); 619 return &owned_canvas_.value();
629 } 620 }
630 621
631 } // namespace gfx 622 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698