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

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

Issue 1831883002: Use sk_sp-based shader creation APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 | « skia/ext/pixel_ref_utils_unittest.cc ('k') | ui/gfx/render_text.h » ('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 <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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 int x, 411 int x,
412 int y, 412 int y,
413 const SkPath& path, 413 const SkPath& path,
414 const SkPaint& paint) { 414 const SkPaint& paint) {
415 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_); 415 const ImageSkiaRep& image_rep = image.GetRepresentation(image_scale_);
416 if (image_rep.is_null()) 416 if (image_rep.is_null())
417 return; 417 return;
418 418
419 SkMatrix matrix; 419 SkMatrix matrix;
420 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); 420 matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y));
421 skia::RefPtr<SkShader> shader = CreateImageRepShader(
422 image_rep,
423 SkShader::kRepeat_TileMode,
424 matrix);
425
426 SkPaint p(paint); 421 SkPaint p(paint);
427 p.setShader(shader.get()); 422 p.setShader(CreateImageRepShader(image_rep,
423 SkShader::kRepeat_TileMode,
424 matrix));
428 canvas_->drawPath(path, p); 425 canvas_->drawPath(path, p);
429 } 426 }
430 427
431 void Canvas::DrawStringRect(const base::string16& text, 428 void Canvas::DrawStringRect(const base::string16& text,
432 const FontList& font_list, 429 const FontList& font_list,
433 SkColor color, 430 SkColor color,
434 const Rect& display_rect) { 431 const Rect& display_rect) {
435 DrawStringRectWithFlags(text, font_list, color, display_rect, 432 DrawStringRectWithFlags(text, font_list, color, display_rect,
436 DefaultCanvasTextAlignment()); 433 DefaultCanvasTextAlignment());
437 } 434 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // Make a bitmap shader that contains the bitmap we want to draw. This is 548 // Make a bitmap shader that contains the bitmap we want to draw. This is
552 // basically what SkCanvas.drawBitmap does internally, but it gives us 549 // basically what SkCanvas.drawBitmap does internally, but it gives us
553 // more control over quality and will use the mipmap in the source image if 550 // more control over quality and will use the mipmap in the source image if
554 // it has one, whereas drawBitmap won't. 551 // it has one, whereas drawBitmap won't.
555 SkMatrix shader_scale; 552 SkMatrix shader_scale;
556 shader_scale.setScale(SkFloatToScalar(user_scale_x), 553 shader_scale.setScale(SkFloatToScalar(user_scale_x),
557 SkFloatToScalar(user_scale_y)); 554 SkFloatToScalar(user_scale_y));
558 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); 555 shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y));
559 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); 556 shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y));
560 557
561 skia::RefPtr<SkShader> shader = CreateImageRepShaderForScale(
562 image_rep, SkShader::kRepeat_TileMode, shader_scale,
563 remove_image_scale ? image_rep.scale() : 1.f);
564
565 // Set up our paint to use the shader & release our reference (now just owned 558 // Set up our paint to use the shader & release our reference (now just owned
566 // by the paint). 559 // by the paint).
567 SkPaint p(paint); 560 SkPaint p(paint);
568 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); 561 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality);
569 p.setShader(shader.get()); 562 p.setShader(CreateImageRepShaderForScale(
563 image_rep, SkShader::kRepeat_TileMode, shader_scale,
564 remove_image_scale ? image_rep.scale() : 1.f));
570 565
571 // The rect will be filled by the bitmap. 566 // The rect will be filled by the bitmap.
572 canvas_->drawRect(dest_rect, p); 567 canvas_->drawRect(dest_rect, p);
573 } 568 }
574 569
575 } // namespace gfx 570 } // namespace gfx
OLDNEW
« no previous file with comments | « skia/ext/pixel_ref_utils_unittest.cc ('k') | ui/gfx/render_text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698