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

Side by Side Diff: gm/SkLinearBitmapPipelineGM.cpp

Issue 1704583003: Simplified linear pipeline. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix unaligned size problem. Created 4 years, 10 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 "SkCanvas.h"
10 #include "SkColor.h"
11 #include "SkImage.h"
12 #include "SkImageInfo.h"
13 #include "SkLinearBitmapPipeline.h"
14 #include "SkXfermode.h"
15 #include "SkPM4fPriv.h"
16 #include "SkShader.h"
17
18 static void fill_in_bits(SkBitmap& bm, SkIRect ir, SkColor c, bool premul) {
19 bm.allocN32Pixels(ir.width(), ir.height());
20 SkPixmap pm;
21 bm.peekPixels(&pm);
22
23 SkPMColor b = SkColorSetARGBMacro(255, 0, 0, 0);
24 SkPMColor w;
25 if (premul) {
26 w = SkPreMultiplyColor(c);
27 } else {
28 w = SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), SkColorGetB(c));
29 }
30
31 for (int y = 0; y < ir.height(); y++) {
32 for (int x = 0; x < ir.width(); x++) {
33 if ((x ^ y) & 16) {
34 *pm.writable_addr32(x, y) = b;
35 } else {
36 *pm.writable_addr32(x, y) = w;
37 }
38 }
39 }
40 }
41
42 static void draw_rect_orig(SkCanvas* canvas, const SkRect& r, SkColor c, const S kMatrix* mat, bool useBilerp) {
43 const SkIRect ir = r.round();
44
45 SkBitmap bmsrc;
46 fill_in_bits(bmsrc, ir, c, true);
47
48 SkPixmap pmsrc;
49 bmsrc.peekPixels(&pmsrc);
50
51 SkBitmap bmdst;
52 bmdst.allocN32Pixels(ir.width(), ir.height());
53 bmdst.eraseColor(0xFFFFFFFF);
54 SkPixmap pmdst;
55 bmdst.peekPixels(&pmdst);
56
57 SkImageInfo info = SkImageInfo::MakeN32Premul(ir.width(), ir.height(), kLine ar_SkColorProfileType);
58
59 SkAutoTUnref<SkImage> image{SkImage::NewRasterCopy(
60 info, pmsrc.addr32(), pmsrc.rowBytes())};
61 SkPaint paint;
62 int32_t storage[200];
63 SkShader* shader = image->newShader(SkShader::kClamp_TileMode, SkShader::kCl amp_TileMode);
64 if (useBilerp) {
65 paint.setFilterQuality(SkFilterQuality::kLow_SkFilterQuality);
66 } else {
67 paint.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
68 }
69 paint.setShader(shader)->unref();
70 SkASSERT(paint.getShader()->contextSize() <= sizeof(storage));
71
72 SkShader::Context* ctx = paint.getShader()->createContext(
73 {paint, *mat, nullptr},
74 storage);
75
76 for (int y = 0; y < ir.height(); y++) {
77 ctx->shadeSpan(0, y, pmdst.writable_addr32(0, y), ir.width());
78 }
79
80 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr);
81
82 ctx->~Context();
83
84 }
85
86 static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM atrix* mat, bool useBilerp) {
87 const SkIRect ir = r.round();
88
89 SkBitmap bmsrc;
90 fill_in_bits(bmsrc, ir, c, true);
91 SkPixmap pmsrc;
92 bmsrc.peekPixels(&pmsrc);
93
94 SkBitmap bmdst;
95 bmdst.allocN32Pixels(ir.width(), ir.height());
96 bmdst.eraseColor(0xFFFFFFFF);
97 SkPixmap pmdst;
98 bmdst.peekPixels(&pmdst);
99
100 SkPM4f* dstBits = new SkPM4f[ir.width()];
101 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), kPremul_SkA lphaType);
102
103 SkMatrix inv;
104 bool trash = mat->invert(&inv);
105 sk_ignore_unused_variable(trash);
106
107
108 uint32_t flags = 0;
109 //if (kSRGB_SkColorProfileType == profile) {
110 //flags |= SkXfermode::kDstIsSRGB_PM4fFlag;
111 //}
112 const SkXfermode::PM4fState state { nullptr, flags };
113 auto procN = SkXfermode::GetPM4fProcN(SkXfermode::kSrcOver_Mode, flags);
114
115 SkLinearBitmapPipeline pipeline{
116 inv, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, info, pms rc.addr32()};
117
118
119 for (int y = 0; y < ir.height(); y++) {
120 pipeline.shadeSpan4f(0, y, dstBits, ir.width());
121 procN(state, pmdst.writable_addr32(0, y), dstBits, ir.width(), nullptr);
122 }
123
124 delete [] dstBits;
125
126 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr);
127 }
128
129 static void draw_rect_none(SkCanvas* canvas, const SkRect& r, SkColor c) {
130 const SkIRect ir = r.round();
131
132 SkBitmap bm;
133 fill_in_bits(bm, ir, c, true);
134
135 canvas->drawBitmap(bm, r.left(), r.top(), nullptr);
136 }
137
138 /*
139 * Test SkXfer4fProcs directly for src-over, comparing them to current SkColor blits.
140 */
141 DEF_SIMPLE_GM(linear_pipeline, canvas, 580, 1400) {
142 const int IW = 50;
143 const SkScalar W = IW;
144 const SkScalar H = 100;
145
146 const SkColor colors[] = {
147 0x880000FF, 0x8800FF00, 0x88FF0000, 0x88000000,
148 SK_ColorBLUE, SK_ColorGREEN, SK_ColorRED, SK_ColorBLACK,
149 };
150
151 canvas->translate(20, 20);
152
153 SkMatrix mi = SkMatrix::I();
154 SkMatrix mt;
155 mt.setTranslate(8, 8);
156 SkMatrix ms;
157 ms.setScale(2.7f, 2.7f);
158 SkMatrix mr;
159 mr.setRotate(10);
160
161 const SkMatrix* mats[] = {nullptr, &mi, &mt, &ms, &mr};
162
163 const SkRect r = SkRect::MakeWH(W, H);
164 bool useBilerp = false;
165 while (true) {
166 canvas->save();
167 for (auto mat : mats) {
168 canvas->save();
169 for (SkColor c : colors) {
170 if (mat == nullptr) {
171 SkPaint p;
172 p.setColor(c);
173 draw_rect_none(canvas, r, c);
174 canvas->translate(W + 20, 0);
175 draw_rect_none(canvas, r, c);
176
177 } else {
178 draw_rect_orig(canvas, r, c, mat, useBilerp);
179 canvas->translate(W + 20, 0);
180 draw_rect_fp(canvas, r, c, mat, useBilerp);
181 }
182 canvas->translate(W + 20, 0);
183 }
184 canvas->restore();
185 canvas->translate(0, H + 20);
186 }
187 canvas->restore();
188 canvas->translate(0, (H + 20) * SK_ARRAY_COUNT(mats));
189 if (useBilerp) break;
190 useBilerp = true;
191 }
192 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698