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

Side by Side Diff: gm/drawminibitmaprect.cpp

Issue 1294513002: Add GM to test drawing atlas case (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: change strict for fast Created 5 years, 4 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
(Empty)
1 /*
robertphillips 2015/08/13 18:17:52 2015 ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
robertphillips 2015/08/13 18:17:51 Do we need the blur headers ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
11 #include "SkColorPriv.h"
12 #include "SkGradientShader.h"
13 #include "SkShader.h"
14 #include "SkImage.h"
15 #include "SkRandom.h"
16
17 static SkImage* image_from_bitmap(const SkBitmap& bm) {
18 SkBitmap b(bm);
19 b.lockPixels();
20 return SkImage::NewRasterCopy(b.info(), b.getPixels(), b.rowBytes());
21 }
22
robertphillips 2015/08/13 18:17:52 Can we pass the GM's canvas in here and use newSur
23 static SkImage* makebm(SkBitmap* bm, int w, int h) {
24 bm->allocN32Pixels(w, h);
25 bm->eraseColor(SK_ColorTRANSPARENT);
26
27 SkCanvas canvas(*bm);
28
29 SkScalar wScalar = SkIntToScalar(w);
30 SkScalar hScalar = SkIntToScalar(h);
31
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
32 SkPoint pt = { wScalar / 2, hScalar / 2 };
33
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
34 SkScalar radius = 4 * SkMaxScalar(wScalar, hScalar);
35
robertphillips 2015/08/13 18:17:52 const ? static ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
36 SkColor colors[] = { SK_ColorRED, SK_ColorYELLOW,
37 SK_ColorGREEN, SK_ColorMAGENTA,
38 SK_ColorBLUE, SK_ColorCYAN,
39 SK_ColorRED};
40
robertphillips 2015/08/13 18:17:52 const ? static ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
41 SkScalar pos[] = {0,
42 SK_Scalar1 / 6,
43 2 * SK_Scalar1 / 6,
44 3 * SK_Scalar1 / 6,
45 4 * SK_Scalar1 / 6,
46 5 * SK_Scalar1 / 6,
47 SK_Scalar1};
48
robertphillips 2015/08/13 18:17:51 SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(
joshualitt 2015/08/13 19:31:27 Acknowledged.
49 SkPaint paint;
50 SkRect rect = SkRect::MakeWH(wScalar, hScalar);
51 SkMatrix mat = SkMatrix::I();
52 for (int i = 0; i < 4; ++i) {
53 paint.setShader(SkGradientShader::CreateRadial(
54 pt, radius,
55 colors, pos,
56 SK_ARRAY_COUNT(colors),
57 SkShader::kRepeat_TileMode,
58 0, &mat))->unref();
59 canvas.drawRect(rect, paint);
60 rect.inset(wScalar / 8, hScalar / 8);
61 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
62 }
63 // Let backends know we won't change this, so they don't have to deep copy i t defensively.
64 bm->setImmutable();
65
66 return image_from_bitmap(*bm);
67 }
68
69 static const int gSize = 1024;
70 static const int gBmpSize = 2048;
71
robertphillips 2015/08/13 18:17:52 // This GM calls drawImageRect several times using
joshualitt 2015/08/13 19:31:27 Acknowledged.
72 class DrawMiniBitmapRectGM : public skiagm::GM {
73 public:
74 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) {
75 fName.set("drawminibitmaprect");
76 if (fAA) {
77 fName.appendf("_aa");
78 }
79 }
80
81 bool fAA;
robertphillips 2015/08/13 18:17:52 Do we need to keep fLargeBitmap around?
joshualitt 2015/08/13 19:31:27 Acknowledged.
82 SkBitmap fLargeBitmap;
83 SkAutoTUnref<SkImage> fImage;
84 SkString fName;
85
86 protected:
87 SkString onShortName() override { return fName; }
88
89 SkISize onISize() override { return SkISize::Make(gSize, gSize); }
90
91 void onOnceBeforeDraw() override {
92 fImage.reset(makebm(&fLargeBitmap, gBmpSize, gBmpSize));
93 }
94
95 void onDraw(SkCanvas* canvas) override {
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
96 SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
97 static const int kMaxSrcRectSize = 1 << (SkNextLog2(gBmpSize) + 2);
98
99 static const int kPadX = 30;
100 static const int kPadY = 40;
101
102 int rowCount = 0;
103 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
robertphillips 2015/08/13 18:17:52 Is there a restore to match this ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
104 canvas->save();
105 SkRandom random;
106
107 SkPaint paint;
108 paint.setAntiAlias(fAA);
109 for (int w = 1; w <= kMaxSrcRectSize; w *= 3) {
110 for (int h = 1; h <= kMaxSrcRectSize; h *= 3) {
111
robertphillips 2015/08/13 18:17:52 const ?
joshualitt 2015/08/13 19:31:27 Acknowledged.
112 SkIRect srcRect = SkIRect::MakeXYWH((gBmpSize - w) / 2, (gBmpSiz e - h) / 2, w, h);
113 canvas->save();
114 switch (random.nextU() % 3) {
115 case 0:
116 canvas->rotate(random.nextF() * 10.f);
117 break;
118 case 1:
119 canvas->rotate(-random.nextF() * 10.f);
120 break;
121 case 2:
122 // rect stays rect
123 break;
124 }
125 canvas->drawImageRect(fImage, srcRect, dstRect, &paint,
126 SkCanvas::kFast_SrcRectConstraint);
127 canvas->restore();
128
129 canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
130 ++rowCount;
131 if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) {
132 canvas->restore();
133 canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
134 canvas->save();
135 rowCount = 0;
136 }
137 }
138 }
139
140 }
141
142 private:
143 typedef skiagm::GM INHERITED;
144 };
145
146 DEF_GM( return new DrawMiniBitmapRectGM(true); )
147 DEF_GM( return new DrawMiniBitmapRectGM(false); )
148
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