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

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

Issue 1849763002: Use sk_sp-based shader setting APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review constness + rebase Created 4 years, 8 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 | « third_party/WebKit/Source/platform/graphics/filters/FETurbulence.cpp ('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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); 493 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
494 if (image_rep.is_null()) 494 if (image_rep.is_null())
495 return false; 495 return false;
496 496
497 SkMatrix shader_scale; 497 SkMatrix shader_scale;
498 shader_scale.setScale(SkFloatToScalar(tile_scale_x), 498 shader_scale.setScale(SkFloatToScalar(tile_scale_x),
499 SkFloatToScalar(tile_scale_y)); 499 SkFloatToScalar(tile_scale_y));
500 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); 500 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
501 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); 501 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
502 502
503 // setShader() takes ownership of the created shader.
504 paint->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode, 503 paint->setShader(CreateImageRepShader(image_rep, SkShader::kRepeat_TileMode,
danakj 2016/03/31 19:50:02 How does it work? CreateIRShader returns a skia::R
f(malita) 2016/03/31 19:51:44 I had the exact same headscratch, but sync your tr
danakj 2016/03/31 19:53:22 Oh ok, codesearch isn't updated yet. LGTM
505 shader_scale).get()); 504 shader_scale));
506 paint->setXfermodeMode(SkXfermode::kSrcOver_Mode); 505 paint->setXfermodeMode(SkXfermode::kSrcOver_Mode);
507 return true; 506 return true;
508 } 507 }
509 508
510 void Canvas::Transform(const gfx::Transform& transform) { 509 void Canvas::Transform(const gfx::Transform& transform) {
511 canvas_->concat(transform.matrix()); 510 canvas_->concat(transform.matrix());
512 } 511 }
513 512
514 bool Canvas::IntersectsClipRect(const SkRect& rect) { 513 bool Canvas::IntersectsClipRect(const SkRect& rect) {
515 SkRect clip; 514 SkRect clip;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // Make a bitmap shader that contains the bitmap we want to draw. This is 547 // Make a bitmap shader that contains the bitmap we want to draw. This is
549 // basically what SkCanvas.drawBitmap does internally, but it gives us 548 // basically what SkCanvas.drawBitmap does internally, but it gives us
550 // more control over quality and will use the mipmap in the source image if 549 // more control over quality and will use the mipmap in the source image if
551 // it has one, whereas drawBitmap won't. 550 // it has one, whereas drawBitmap won't.
552 SkMatrix shader_scale; 551 SkMatrix shader_scale;
553 shader_scale.setScale(SkFloatToScalar(user_scale_x), 552 shader_scale.setScale(SkFloatToScalar(user_scale_x),
554 SkFloatToScalar(user_scale_y)); 553 SkFloatToScalar(user_scale_y));
555 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); 554 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
556 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); 555 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
557 556
558 // Set up our paint to use the shader & release our reference (now just owned
559 // by the paint).
560 SkPaint p(paint); 557 SkPaint p(paint);
561 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); 558 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
562 p.setShader(CreateImageRepShaderForScale( 559 p.setShader(CreateImageRepShaderForScale(
563 image_rep, SkShader::kRepeat_TileMode, shader_scale, 560 image_rep, SkShader::kRepeat_TileMode, shader_scale,
564 remove_image_scale ? image_rep.scale() : 1.f)); 561 remove_image_scale ? image_rep.scale() : 1.f));
565 562
566 // The rect will be filled by the bitmap. 563 // The rect will be filled by the bitmap.
567 canvas_->drawRect(dest_rect, p); 564 canvas_->drawRect(dest_rect, p);
568 } 565 }
569 566
570 } // namespace gfx 567 } // namespace gfx
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/graphics/filters/FETurbulence.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698