OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBlurMask.h" | 9 #include "SkBlurMask.h" |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 for (int y = 0; y < bm.height(); y++) { | 26 for (int y = 0; y < bm.height(); y++) { |
27 uint32_t* p = bm.getAddr32(0, y); | 27 uint32_t* p = bm.getAddr32(0, y); |
28 for (int x = 0; x < bm.width(); x++) { | 28 for (int x = 0; x < bm.width(); x++) { |
29 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; | 29 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; |
30 } | 30 } |
31 } | 31 } |
32 bm.unlockPixels(); | 32 bm.unlockPixels(); |
33 return bm; | 33 return bm; |
34 } | 34 } |
35 | 35 |
36 static SkImage* makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, int h) { | 36 static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, in
t h) { |
37 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); | 37 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); |
38 | 38 |
39 SkAutoTUnref<SkSurface> surface(origCanvas->newSurface(info)); | 39 SkAutoTUnref<SkSurface> surface(origCanvas->newSurface(info)); |
40 if (nullptr == surface) { | 40 if (nullptr == surface) { |
41 // picture canvas will return null, so fall-back to raster | 41 // picture canvas will return null, so fall-back to raster |
42 surface.reset(SkSurface::NewRaster(info)); | 42 surface.reset(SkSurface::NewRaster(info)); |
43 } | 43 } |
44 | 44 |
45 SkCanvas* canvas = surface->getCanvas(); | 45 SkCanvas* canvas = surface->getCanvas(); |
46 | 46 |
(...skipping 27 matching lines...) Expand all Loading... |
74 pt, radius, | 74 pt, radius, |
75 colors, pos, | 75 colors, pos, |
76 SK_ARRAY_COUNT(colors), | 76 SK_ARRAY_COUNT(colors), |
77 SkShader::kRepeat_TileMode, | 77 SkShader::kRepeat_TileMode, |
78 0, &mat)); | 78 0, &mat)); |
79 canvas->drawRect(rect, paint); | 79 canvas->drawRect(rect, paint); |
80 rect.inset(wScalar / 8, hScalar / 8); | 80 rect.inset(wScalar / 8, hScalar / 8); |
81 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); | 81 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); |
82 } | 82 } |
83 | 83 |
84 SkImage* image = surface->newImageSnapshot(); | 84 auto image = surface->makeImageSnapshot(); |
85 | 85 |
86 SkBitmap tempBM; | 86 SkBitmap tempBM; |
87 | 87 |
88 #if SK_SUPPORT_GPU | 88 #if SK_SUPPORT_GPU |
89 if (GrTexture* texture = as_IB(image)->peekTexture()) { | 89 if (GrTexture* texture = as_IB(image)->peekTexture()) { |
90 GrWrapTextureInBitmap(texture, image->width(), image->height(), image->i
sOpaque(), &tempBM); | 90 GrWrapTextureInBitmap(texture, image->width(), image->height(), image->i
sOpaque(), &tempBM); |
91 } else | 91 } else |
92 #endif | 92 #endif |
93 { | 93 { |
94 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode); | 94 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode); |
(...skipping 23 matching lines...) Expand all Loading... |
118 | 118 |
119 class DrawBitmapRectGM : public skiagm::GM { | 119 class DrawBitmapRectGM : public skiagm::GM { |
120 public: | 120 public: |
121 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { | 121 DrawBitmapRectGM(DrawRectRectProc proc, const char suffix[]) : fProc(proc) { |
122 fName.set("drawbitmaprect"); | 122 fName.set("drawbitmaprect"); |
123 if (suffix) { | 123 if (suffix) { |
124 fName.append(suffix); | 124 fName.append(suffix); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 DrawRectRectProc* fProc; | 128 DrawRectRectProc* fProc; |
129 SkBitmap fLargeBitmap; | 129 SkBitmap fLargeBitmap; |
130 SkAutoTUnref<SkImage> fImage; | 130 sk_sp<SkImage> fImage; |
131 SkString fName; | 131 SkString fName; |
132 | 132 |
133 protected: | 133 protected: |
134 SkString onShortName() override { return fName; } | 134 SkString onShortName() override { return fName; } |
135 | 135 |
136 SkISize onISize() override { return SkISize::Make(gSize, gSize); } | 136 SkISize onISize() override { return SkISize::Make(gSize, gSize); } |
137 | 137 |
138 void setupImage(SkCanvas* canvas) { | 138 void setupImage(SkCanvas* canvas) { |
139 fImage.reset(makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize)); | 139 fImage = makebm(canvas, &fLargeBitmap, gBmpSize, gBmpSize); |
140 } | 140 } |
141 | 141 |
142 void onDraw(SkCanvas* canvas) override { | 142 void onDraw(SkCanvas* canvas) override { |
143 if (!fImage) { | 143 if (!fImage) { |
144 this->setupImage(canvas); | 144 this->setupImage(canvas); |
145 } | 145 } |
146 | 146 |
147 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; | 147 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; |
148 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2); | 148 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2); |
149 | 149 |
(...skipping 15 matching lines...) Expand all Loading... |
165 canvas->drawText(title.c_str(), title.size(), 0, | 165 canvas->drawText(title.c_str(), title.size(), 0, |
166 titleHeight, blackPaint); | 166 titleHeight, blackPaint); |
167 | 167 |
168 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); | 168 canvas->translate(0, SK_Scalar1 * kPadY / 2 + titleHeight); |
169 int rowCount = 0; | 169 int rowCount = 0; |
170 canvas->save(); | 170 canvas->save(); |
171 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { | 171 for (int w = 1; w <= kMaxSrcRectSize; w *= 4) { |
172 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { | 172 for (int h = 1; h <= kMaxSrcRectSize; h *= 4) { |
173 | 173 |
174 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz
e - h) / 2, w, h); | 174 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz
e - h) / 2, w, h); |
175 fProc(canvas, fImage, fLargeBitmap, srcRect, dstRect); | 175 fProc(canvas, fImage.get(), fLargeBitmap, srcRect, dstRect); |
176 | 176 |
177 SkString label; | 177 SkString label; |
178 label.appendf("%d x %d", w, h); | 178 label.appendf("%d x %d", w, h); |
179 blackPaint.setAntiAlias(true); | 179 blackPaint.setAntiAlias(true); |
180 blackPaint.setStyle(SkPaint::kFill_Style); | 180 blackPaint.setStyle(SkPaint::kFill_Style); |
181 blackPaint.setTextSize(SK_Scalar1 * 10); | 181 blackPaint.setTextSize(SK_Scalar1 * 10); |
182 SkScalar baseline = dstRect.height() + | 182 SkScalar baseline = dstRect.height() + |
183 blackPaint.getTextSize() + SK_Scalar1 * 3; | 183 blackPaint.getTextSize() + SK_Scalar1 * 3; |
184 canvas->drawText(label.c_str(), label.size(), | 184 canvas->drawText(label.c_str(), label.size(), |
185 0, baseline, | 185 0, baseline, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); | 220 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 private: | 224 private: |
225 typedef skiagm::GM INHERITED; | 225 typedef skiagm::GM INHERITED; |
226 }; | 226 }; |
227 | 227 |
228 DEF_GM( return new DrawBitmapRectGM(canvasproc, nullptr); ) | 228 DEF_GM( return new DrawBitmapRectGM(canvasproc, nullptr); ) |
229 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) | 229 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) |
OLD | NEW |