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

Side by Side Diff: gm/bitmapsource2.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 | « bench/MergeBench.cpp ('k') | gm/displacement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 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"
9 #include "SkBitmapSource.h"
10
11 namespace skiagm {
12
13 // This GM reproduces the issue in crbug.com/472795. The SkBitmapSource image
14 // is shifted for high quality mode between cpu and gpu.
15 class BitmapSourceGM : public GM {
16 public:
17 BitmapSourceGM(const char* suffix, SkFilterQuality filter) : fSuffix(suffix) , fFilter(filter) {
18 this->setBGColor(0xFFFFFFFF);
19 }
20
21 protected:
22 SkString onShortName() override {
23 SkString name("bitmapsrc2_");
24 name.append(fSuffix);
25 return name;
26 }
27
28 SkISize onISize() override { return SkISize::Make(256, 256); }
29
30 // Create a bitmap with high frequency vertical stripes
31 void onOnceBeforeDraw() override {
32 static const SkPMColor gColors[] = {
33 SK_ColorRED, SK_ColorGRAY,
34 SK_ColorGREEN, SK_ColorGRAY,
35 SK_ColorBLUE, SK_ColorGRAY,
36 SK_ColorCYAN, SK_ColorGRAY,
37 SK_ColorMAGENTA, SK_ColorGRAY,
38 SK_ColorYELLOW, SK_ColorGRAY,
39 SK_ColorWHITE, SK_ColorGRAY,
40 };
41
42 fBM.allocN32Pixels(kImageSize, kImageSize, true);
43
44 SkCanvas canvas(fBM);
45
46 int curColor = 0;
47
48 for (int x = 0; x < kImageSize; x += 3) {
49 SkRect r = SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(0),
50 SkIntToScalar(3), SkIntToScalar(kImageSi ze));
51 SkPaint p;
52 p.setColor(gColors[curColor]);
53 canvas.drawRect(r, p);
54
55 curColor = (curColor+1) % SK_ARRAY_COUNT(gColors);
56 }
57 }
58
59 void onDraw(SkCanvas* canvas) override {
60 SkRect srcRect = SkRect::MakeLTRB(0, 0,
61 SkIntToScalar(kImageSize), SkIntToScal ar(kImageSize));
62 SkRect dstRect = SkRect::MakeLTRB(0.75f, 0.75f, 225.75f, 225.75f);
63
64 SkAutoTUnref<SkImageFilter> filter(SkBitmapSource::Create(fBM, srcRect, dstRect, fFilter));
65
66 SkPaint p;
67 p.setImageFilter(filter);
68
69 canvas->saveLayer(nullptr, &p);
70 canvas->restore();
71 }
72
73 private:
74 static const int kImageSize = 503;
75
76 SkString fSuffix;
77 SkFilterQuality fFilter;
78 SkBitmap fBM;
79
80 typedef GM INHERITED;
81 };
82
83 //////////////////////////////////////////////////////////////////////////////
84
85 DEF_GM(return new BitmapSourceGM("none", kNone_SkFilterQuality);)
86 DEF_GM(return new BitmapSourceGM("low", kLow_SkFilterQuality);)
87 DEF_GM(return new BitmapSourceGM("med", kMedium_SkFilterQuality);)
88 DEF_GM(return new BitmapSourceGM("high", kHigh_SkFilterQuality);)
89 }
OLDNEW
« no previous file with comments | « bench/MergeBench.cpp ('k') | gm/displacement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698