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

Side by Side Diff: gm/pictureimagefilter.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 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 | « gm/picture.cpp ('k') | gm/pictureimagegenerator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 9
10 #include "SkPictureImageFilter.h" 10 #include "SkPictureImageFilter.h"
(...skipping 15 matching lines...) Expand all
26 SkPictureRecorder recorder; 26 SkPictureRecorder recorder;
27 SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0); 27 SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0);
28 canvas->clear(SK_ColorBLACK); 28 canvas->clear(SK_ColorBLACK);
29 SkPaint paint; 29 SkPaint paint;
30 paint.setAntiAlias(true); 30 paint.setAntiAlias(true);
31 sk_tool_utils::set_portable_typeface(&paint); 31 sk_tool_utils::set_portable_typeface(&paint);
32 paint.setColor(0xFFFFFFFF); 32 paint.setColor(0xFFFFFFFF);
33 paint.setTextSize(SkIntToScalar(96)); 33 paint.setTextSize(SkIntToScalar(96));
34 const char* str = "e"; 34 const char* str = "e";
35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint); 35 canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
36 fPicture.reset(recorder.endRecording()); 36 fPicture = recorder.finishRecordingAsPicture();
37 } 37 }
38 38
39 SkISize onISize() override { return SkISize::Make(600, 300); } 39 SkISize onISize() override { return SkISize::Make(600, 300); }
40 40
41 void onOnceBeforeDraw() override { 41 void onOnceBeforeDraw() override {
42 this->makePicture(); 42 this->makePicture();
43 } 43 }
44 44
45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma geFilter* filter) { 45 static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkIma geFilter* filter) {
46 SkPaint paint; 46 SkPaint paint;
47 paint.setImageFilter(filter); 47 paint.setImageFilter(filter);
48 canvas->save(); 48 canvas->save();
49 canvas->clipRect(clipRect); 49 canvas->clipRect(clipRect);
50 canvas->drawPaint(paint); 50 canvas->drawPaint(paint);
51 canvas->restore(); 51 canvas->restore();
52 } 52 }
53 53
54 void onDraw(SkCanvas* canvas) override { 54 void onDraw(SkCanvas* canvas) override {
55 canvas->clear(SK_ColorBLACK); 55 canvas->clear(SK_ColorBLACK);
56 { 56 {
57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30); 57 SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0); 58 SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); 59 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
60 SkAutoTUnref<SkImageFilter> pictureSource( 60 SkAutoTUnref<SkImageFilter> pictureSource(
61 SkPictureImageFilter::Create(fPicture)); 61 SkPictureImageFilter::Create(fPicture.get()));
62 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect( 62 SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(
63 SkPictureImageFilter::Create(fPicture, srcRect)); 63 SkPictureImageFilter::Create(fPicture.get(), srcRect));
64 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect( 64 SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(
65 SkPictureImageFilter::Create(fPicture, emptyRect)); 65 SkPictureImageFilter::Create(fPicture.get(), emptyRect));
66 SkAutoTUnref<SkImageFilter> pictureSourceResampled( 66 SkAutoTUnref<SkImageFilter> pictureSourceResampled(
67 SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cu llRect(), 67 SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPictu re->cullRect(),
68 kLow_SkFilterQuality)); 68 kLow_SkFilterQuality));
69 SkAutoTUnref<SkImageFilter> pictureSourcePixelated( 69 SkAutoTUnref<SkImageFilter> pictureSourcePixelated(
70 SkPictureImageFilter::CreateForLocalSpace(fPicture, fPicture->cu llRect(), 70 SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPictu re->cullRect(),
71 kNone_SkFilterQuality)); 71 kNone_SkFilterQuality));
72 72
73 canvas->save(); 73 canvas->save();
74 // Draw the picture unscaled. 74 // Draw the picture unscaled.
75 fillRectFiltered(canvas, bounds, pictureSource); 75 fillRectFiltered(canvas, bounds, pictureSource);
76 canvas->translate(SkIntToScalar(100), 0); 76 canvas->translate(SkIntToScalar(100), 0);
77 77
78 // Draw an unscaled subset of the source picture. 78 // Draw an unscaled subset of the source picture.
79 fillRectFiltered(canvas, bounds, pictureSourceSrcRect); 79 fillRectFiltered(canvas, bounds, pictureSourceSrcRect);
80 canvas->translate(SkIntToScalar(100), 0); 80 canvas->translate(SkIntToScalar(100), 0);
(...skipping 14 matching lines...) Expand all
95 canvas->translate(srcRect.width(), 0); 95 canvas->translate(srcRect.width(), 0);
96 fillRectFiltered(canvas, srcRect, pictureSourceResampled); 96 fillRectFiltered(canvas, srcRect, pictureSourceResampled);
97 97
98 // Draw the picture scaled, pixelated 98 // Draw the picture scaled, pixelated
99 canvas->translate(srcRect.width(), 0); 99 canvas->translate(srcRect.width(), 0);
100 fillRectFiltered(canvas, srcRect, pictureSourcePixelated); 100 fillRectFiltered(canvas, srcRect, pictureSourcePixelated);
101 } 101 }
102 } 102 }
103 103
104 private: 104 private:
105 SkAutoTUnref<SkPicture> fPicture; 105 sk_sp<SkPicture> fPicture;
106 typedef GM INHERITED; 106 typedef GM INHERITED;
107 }; 107 };
108 108
109 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
110 110
111 DEF_GM( return new PictureImageFilterGM; ) 111 DEF_GM( return new PictureImageFilterGM; )
OLDNEW
« no previous file with comments | « gm/picture.cpp ('k') | gm/pictureimagegenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698