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

Side by Side Diff: gm/drawminibitmaprect.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage 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/drawbitmaprect.cpp ('k') | gm/etc1bitmap.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 2015 Google Inc. 2 * Copyright 2015 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 #include "SkColorPriv.h" 9 #include "SkColorPriv.h"
10 #include "SkGradientShader.h" 10 #include "SkGradientShader.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkRandom.h" 12 #include "SkRandom.h"
13 #include "SkShader.h" 13 #include "SkShader.h"
14 #include "SkSurface.h" 14 #include "SkSurface.h"
15 15
16 static SkImage* makebm(SkCanvas* caller, int w, int h) { 16 static sk_sp<SkImage> makebm(SkCanvas* caller, int w, int h) {
17 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); 17 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
18 SkAutoTUnref<SkSurface> surface(caller->newSurface(info)); 18 SkAutoTUnref<SkSurface> surface(caller->newSurface(info));
19 if (nullptr == surface) { 19 if (nullptr == surface) {
20 surface.reset(SkSurface::NewRaster(info)); 20 surface.reset(SkSurface::NewRaster(info));
21 } 21 }
22 SkCanvas* canvas = surface->getCanvas(); 22 SkCanvas* canvas = surface->getCanvas();
23 23
24 const SkScalar wScalar = SkIntToScalar(w); 24 const SkScalar wScalar = SkIntToScalar(w);
25 const SkScalar hScalar = SkIntToScalar(h); 25 const SkScalar hScalar = SkIntToScalar(h);
26 26
(...skipping 22 matching lines...) Expand all
49 paint.setShader(SkGradientShader::MakeRadial( 49 paint.setShader(SkGradientShader::MakeRadial(
50 pt, radius, 50 pt, radius,
51 colors, pos, 51 colors, pos,
52 SK_ARRAY_COUNT(colors), 52 SK_ARRAY_COUNT(colors),
53 SkShader::kRepeat_TileMode, 53 SkShader::kRepeat_TileMode,
54 0, &mat)); 54 0, &mat));
55 canvas->drawRect(rect, paint); 55 canvas->drawRect(rect, paint);
56 rect.inset(wScalar / 8, hScalar / 8); 56 rect.inset(wScalar / 8, hScalar / 8);
57 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); 57 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
58 } 58 }
59 return surface->newImageSnapshot(); 59 return surface->makeImageSnapshot();
60 } 60 }
61 61
62 static const int gSize = 1024; 62 static const int gSize = 1024;
63 static const int gSurfaceSize = 2048; 63 static const int gSurfaceSize = 2048;
64 64
65 // This GM calls drawImageRect several times using the same texture. This is 65 // This GM calls drawImageRect several times using the same texture. This is
66 // intended to exercise batching of these calls. 66 // intended to exercise batching of these calls.
67 class DrawMiniBitmapRectGM : public skiagm::GM { 67 class DrawMiniBitmapRectGM : public skiagm::GM {
68 public: 68 public:
69 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) { 69 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) {
70 fName.set("drawminibitmaprect"); 70 fName.set("drawminibitmaprect");
71 if (fAA) { 71 if (fAA) {
72 fName.appendf("_aa"); 72 fName.appendf("_aa");
73 } 73 }
74 } 74 }
75 75
76 protected: 76 protected:
77 SkString onShortName() override { return fName; } 77 SkString onShortName() override { return fName; }
78 78
79 SkISize onISize() override { return SkISize::Make(gSize, gSize); } 79 SkISize onISize() override { return SkISize::Make(gSize, gSize); }
80 80
81 void onDraw(SkCanvas* canvas) override { 81 void onDraw(SkCanvas* canvas) override {
82 if (nullptr == fImage) { 82 if (nullptr == fImage) {
83 fImage.reset(makebm(canvas, gSurfaceSize, gSurfaceSize)); 83 fImage = makebm(canvas, gSurfaceSize, gSurfaceSize);
84 } 84 }
85 85
86 const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; 86 const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
87 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2); 87 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2);
88 88
89 static const int kPadX = 30; 89 static const int kPadX = 30;
90 static const int kPadY = 40; 90 static const int kPadY = 40;
91 91
92 int rowCount = 0; 92 int rowCount = 0;
93 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY)); 93 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
(...skipping 12 matching lines...) Expand all
106 case 0: 106 case 0:
107 canvas->rotate(random.nextF() * 10.f); 107 canvas->rotate(random.nextF() * 10.f);
108 break; 108 break;
109 case 1: 109 case 1:
110 canvas->rotate(-random.nextF() * 10.f); 110 canvas->rotate(-random.nextF() * 10.f);
111 break; 111 break;
112 case 2: 112 case 2:
113 // rect stays rect 113 // rect stays rect
114 break; 114 break;
115 } 115 }
116 canvas->drawImageRect(fImage, srcRect, dstRect, &paint, 116 canvas->drawImageRect(fImage.get(), srcRect, dstRect, &paint,
117 SkCanvas::kFast_SrcRectConstraint); 117 SkCanvas::kFast_SrcRectConstraint);
118 canvas->restore(); 118 canvas->restore();
119 119
120 canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0); 120 canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
121 ++rowCount; 121 ++rowCount;
122 if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) { 122 if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) {
123 canvas->restore(); 123 canvas->restore();
124 canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY); 124 canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
125 canvas->save(); 125 canvas->save();
126 rowCount = 0; 126 rowCount = 0;
127 } 127 }
128 } 128 }
129 } 129 }
130 canvas->restore(); 130 canvas->restore();
131 } 131 }
132 132
133 private: 133 private:
134 bool fAA; 134 bool fAA;
135 SkAutoTUnref<SkImage> fImage; 135 sk_sp<SkImage> fImage;
136 SkString fName; 136 SkString fName;
137 137
138 typedef skiagm::GM INHERITED; 138 typedef skiagm::GM INHERITED;
139 }; 139 };
140 140
141 DEF_GM( return new DrawMiniBitmapRectGM(true); ) 141 DEF_GM( return new DrawMiniBitmapRectGM(true); )
142 DEF_GM( return new DrawMiniBitmapRectGM(false); ) 142 DEF_GM( return new DrawMiniBitmapRectGM(false); )
143 143
OLDNEW
« no previous file with comments | « gm/drawbitmaprect.cpp ('k') | gm/etc1bitmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698