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

Side by Side Diff: gm/imagesource2.cpp

Issue 1343123002: Convert unit tests, GMs from SkBitmapSource to SkImagesource (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review comments Created 5 years, 3 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/imagefiltersscaled.cpp ('k') | gm/offsetimagefilter.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 "SkBitmapSource.h" 9 #include "SkImage.h"
10 #include "SkImageSource.h"
11 #include "SkSurface.h"
10 12
11 namespace skiagm { 13 namespace skiagm {
12 14
13 // This GM reproduces the issue in crbug.com/472795. The SkBitmapSource image 15 // This GM reproduces the issue in crbug.com/472795. The SkImageSource image
14 // is shifted for high quality mode between cpu and gpu. 16 // is shifted for high quality mode between cpu and gpu.
15 class BitmapSourceGM : public GM { 17 class ImageSourceGM : public GM {
16 public: 18 public:
17 BitmapSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix) , fFilter(filter) { 19 ImageSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix), fFilter(filter) {
18 this->setBGColor(0xFFFFFFFF); 20 this->setBGColor(0xFFFFFFFF);
19 } 21 }
20 22
21 protected: 23 protected:
22 SkString onShortName() override { 24 SkString onShortName() override {
23 SkString name("bitmapsrc2_"); 25 SkString name("imagesrc2_");
24 name.append(fSuffix); 26 name.append(fSuffix);
25 return name; 27 return name;
26 } 28 }
27 29
28 SkISize onISize() override { return SkISize::Make(256, 256); } 30 SkISize onISize() override { return SkISize::Make(256, 256); }
29 31
30 // Create a bitmap with high frequency vertical stripes 32 // Create an image with high frequency vertical stripes
31 void onOnceBeforeDraw() override { 33 void onOnceBeforeDraw() override {
32 static const SkPMColor gColors[] = { 34 static const SkPMColor gColors[] = {
33 SK_ColorRED, SK_ColorGRAY, 35 SK_ColorRED, SK_ColorGRAY,
34 SK_ColorGREEN, SK_ColorGRAY, 36 SK_ColorGREEN, SK_ColorGRAY,
35 SK_ColorBLUE, SK_ColorGRAY, 37 SK_ColorBLUE, SK_ColorGRAY,
36 SK_ColorCYAN, SK_ColorGRAY, 38 SK_ColorCYAN, SK_ColorGRAY,
37 SK_ColorMAGENTA, SK_ColorGRAY, 39 SK_ColorMAGENTA, SK_ColorGRAY,
38 SK_ColorYELLOW, SK_ColorGRAY, 40 SK_ColorYELLOW, SK_ColorGRAY,
39 SK_ColorWHITE, SK_ColorGRAY, 41 SK_ColorWHITE, SK_ColorGRAY,
40 }; 42 };
41 43
42 fBM.allocN32Pixels(kImageSize, kImageSize, true); 44 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(kImageSize , kImageSize));
43 45 SkCanvas* canvas = surface->getCanvas();
44 SkCanvas canvas(fBM);
45 46
46 int curColor = 0; 47 int curColor = 0;
47 48
48 for (int x = 0; x < kImageSize; x += 3) { 49 for (int x = 0; x < kImageSize; x += 3) {
49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0), 50 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
50 SkIntToScalar(3), SkIntToScalar(kImageSi ze)); 51 SkIntToScalar(3), SkIntToScalar(kImageSi ze));
51 SkPaint p; 52 SkPaint p;
52 p.setColor(gColors[curColor]); 53 p.setColor(gColors[curColor]);
53 canvas.drawRect(r, p); 54 canvas->drawRect(r, p);
54 55
55 curColor = (curColor+1) % SK_ARRAY_COUNT(gColors); 56 curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
56 } 57 }
58
59 fImage.reset(surface->newImageSnapshot());
57 } 60 }
58 61
59 void onDraw(SkCanvas* canvas) override { 62 void onDraw(SkCanvas* canvas) override {
60 SkRect srcRect = SkRect::MakeLTRB(0, 0, 63 SkRect srcRect = SkRect::MakeLTRB(0, 0,
61 SkIntToScalar(kImageSize), SkIntToScal ar(kImageSize)); 64 SkIntToScalar(kImageSize), SkIntToScal ar(kImageSize));
62 SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f); 65 SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
63 66
64 SkAutoTUnref<SkImageFilter> filter(SkBitmapSource::Create(fBM, srcRect, dstRect, fFilter)); 67 SkAutoTUnref<SkImageFilter> filter(
68 SkImageSource::Create(fImage, srcRect, dstRect, fFilter));
65 69
66 SkPaint p; 70 SkPaint p;
67 p.setImageFilter(filter); 71 p.setImageFilter(filter);
68 72
69 canvas->saveLayer(nullptr, &p); 73 canvas->saveLayer(nullptr, &p);
70 canvas->restore(); 74 canvas->restore();
71 } 75 }
72 76
73 private: 77 private:
74 static const int kImageSize = 503; 78 static const int kImageSize = 503;
75 79
76 SkString fSuffix; 80 SkString fSuffix;
77 SkFilterQuality fFilter; 81 SkFilterQuality fFilter;
78 SkBitmap fBM; 82 SkAutoTUnref<SkImage> fImage;
79 83
80 typedef GM INHERITED; 84 typedef GM INHERITED;
81 }; 85 };
82 86
83 ////////////////////////////////////////////////////////////////////////////// 87 //////////////////////////////////////////////////////////////////////////////
84 88
85 DEF_GM(return new BitmapSourceGM("none", kNone_SkFilterQuality);) 89 DEF_GM(return new ImageSourceGM("none", kNone_SkFilterQuality);)
86 DEF_GM(return new BitmapSourceGM("low", kLow_SkFilterQuality);) 90 DEF_GM(return new ImageSourceGM("low", kLow_SkFilterQuality);)
87 DEF_GM(return new BitmapSourceGM("med", kMedium_SkFilterQuality);) 91 DEF_GM(return new ImageSourceGM("med", kMedium_SkFilterQuality);)
88 DEF_GM(return new BitmapSourceGM("high", kHigh_SkFilterQuality);) 92 DEF_GM(return new ImageSourceGM("high", kHigh_SkFilterQuality);)
89 } 93 }
OLDNEW
« no previous file with comments | « gm/imagefiltersscaled.cpp ('k') | gm/offsetimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698