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

Side by Side Diff: gm/drawbitmaprect.cpp

Issue 2148793003: Stop testing texture-backed bitmaps in drawbitmaprect GM (Closed) Base URL: https://chromium.googlesource.com/skia.git@hidegrwrap
Patch Set: Created 4 years, 5 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 | « no previous file | 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 /* 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"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkGradientShader.h" 12 #include "SkGradientShader.h"
13 #include "SkImage.h" 13 #include "SkImage.h"
14 #include "SkImage_Base.h" 14 #include "SkImage_Base.h"
15 #include "SkMathPriv.h" 15 #include "SkMathPriv.h"
16 #include "SkShader.h" 16 #include "SkShader.h"
17 #include "SkSurface.h" 17 #include "SkSurface.h"
18 18
19 #if SK_SUPPORT_GPU
20 #include "SkGrPriv.h"
21 #endif
22 19
23 static SkBitmap make_chessbm(int w, int h) { 20 static SkBitmap make_chessbm(int w, int h) {
24 SkBitmap bm; 21 SkBitmap bm;
25 bm.allocN32Pixels(w, h); 22 bm.allocN32Pixels(w, h);
26 23
27 for (int y = 0; y < bm.height(); y++) { 24 for (int y = 0; y < bm.height(); y++) {
28 uint32_t* p = bm.getAddr32(0, y); 25 uint32_t* p = bm.getAddr32(0, y);
29 for (int x = 0; x < bm.width(); x++) { 26 for (int x = 0; x < bm.width(); x++) {
30 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK; 27 p[x] = ((x + y) & 1) ? SK_ColorWHITE : SK_ColorBLACK;
31 } 28 }
32 } 29 }
33 bm.unlockPixels(); 30 bm.unlockPixels();
34 return bm; 31 return bm;
35 } 32 }
36 33
34 // Creates a bitmap and a matching image.
37 static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, in t h) { 35 static sk_sp<SkImage> makebm(SkCanvas* origCanvas, SkBitmap* resultBM, int w, in t h) {
38 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h); 36 SkImageInfo info = SkImageInfo::MakeN32Premul(w, h);
39 37
40 auto surface(origCanvas->makeSurface(info)); 38 auto surface(origCanvas->makeSurface(info));
41 if (nullptr == surface) { 39 if (nullptr == surface) {
42 // picture canvas will return null, so fall-back to raster 40 // picture canvas will return null, so fall-back to raster
43 surface = SkSurface::MakeRaster(info); 41 surface = SkSurface::MakeRaster(info);
44 } 42 }
45 43
46 SkCanvas* canvas = surface->getCanvas(); 44 SkCanvas* canvas = surface->getCanvas();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 0, &mat)); 77 0, &mat));
80 canvas->drawRect(rect, paint); 78 canvas->drawRect(rect, paint);
81 rect.inset(wScalar / 8, hScalar / 8); 79 rect.inset(wScalar / 8, hScalar / 8);
82 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4); 80 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
83 } 81 }
84 82
85 auto image = surface->makeImageSnapshot(); 83 auto image = surface->makeImageSnapshot();
86 84
87 SkBitmap tempBM; 85 SkBitmap tempBM;
88 86
89 #if SK_SUPPORT_GPU 87 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode);
90 if (GrTexture* texture = as_IB(image)->peekTexture()) {
91 GrWrapTextureInBitmap(texture, image->width(), image->height(), image->i sOpaque(), &tempBM);
92 } else
93 #endif
94 {
95 image->asLegacyBitmap(&tempBM, SkImage::kRO_LegacyBitmapMode);
96 }
97 88
98 // Let backends know we won't change this, so they don't have to deep copy i t defensively. 89 // Let backends know we won't change this, so they don't have to deep copy i t defensively.
99 tempBM.setImmutable(); 90 tempBM.setImmutable();
100 *resultBM = tempBM; 91 *resultBM = tempBM;
101 92
102 return image; 93 return image;
103 } 94 }
104 95
105 static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect& srcR, 96 static void canvasproc(SkCanvas* canvas, SkImage*, const SkBitmap& bm, const SkI Rect& srcR,
106 const SkRect& dstR) { 97 const SkRect& dstR) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 this->setupImage(canvas); 136 this->setupImage(canvas);
146 } 137 }
147 138
148 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)}; 139 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
149 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2); 140 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
150 141
151 static const int kPadX = 30; 142 static const int kPadX = 30;
152 static const int kPadY = 40; 143 static const int kPadY = 40;
153 SkPaint paint; 144 SkPaint paint;
154 paint.setAlpha(0x20); 145 paint.setAlpha(0x20);
155 canvas->drawBitmapRect(fLargeBitmap, SkRect::MakeIWH(gSize, gSize), &pai nt); 146 canvas->drawImageRect(fImage, SkRect::MakeIWH(gSize, gSize), &paint);
bsalomon 2016/07/13 21:13:08 The GM was (arbitrarily) always using the bitmap r
156 canvas->translate(SK_Scalar1 * kPadX / 2, 147 canvas->translate(SK_Scalar1 * kPadX / 2,
157 SK_Scalar1 * kPadY / 2); 148 SK_Scalar1 * kPadY / 2);
158 SkPaint blackPaint; 149 SkPaint blackPaint;
159 SkScalar titleHeight = SK_Scalar1 * 24; 150 SkScalar titleHeight = SK_Scalar1 * 24;
160 blackPaint.setColor(SK_ColorBLACK); 151 blackPaint.setColor(SK_ColorBLACK);
161 blackPaint.setTextSize(titleHeight); 152 blackPaint.setTextSize(titleHeight);
162 blackPaint.setAntiAlias(true); 153 blackPaint.setAntiAlias(true);
163 sk_tool_utils::set_portable_typeface(&blackPaint); 154 sk_tool_utils::set_portable_typeface(&blackPaint);
164 SkString title; 155 SkString title;
165 title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize); 156 title.printf("Bitmap size: %d x %d", gBmpSize, gBmpSize);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint); 211 canvas->drawBitmapRect(bm, srcRect, dstRect, &paint);
221 } 212 }
222 } 213 }
223 214
224 private: 215 private:
225 typedef skiagm::GM INHERITED; 216 typedef skiagm::GM INHERITED;
226 }; 217 };
227 218
228 DEF_GM( return new DrawBitmapRectGM(canvasproc, nullptr); ) 219 DEF_GM( return new DrawBitmapRectGM(canvasproc, nullptr); )
229 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); ) 220 DEF_GM( return new DrawBitmapRectGM(imageproc, "-imagerect"); )
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698