OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "SkBlitter.h" | 9 #include "SkBlitter.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 bmdst.allocN32Pixels(ir.width(), ir.height()); | 53 bmdst.allocN32Pixels(ir.width(), ir.height()); |
54 bmdst.eraseColor(0xFFFFFFFF); | 54 bmdst.eraseColor(0xFFFFFFFF); |
55 SkPixmap pmdst; | 55 SkPixmap pmdst; |
56 bmdst.peekPixels(&pmdst); | 56 bmdst.peekPixels(&pmdst); |
57 | 57 |
58 SkImageInfo info = SkImageInfo::MakeN32Premul(ir.width(), ir.height(), kLine
ar_SkColorProfileType); | 58 SkImageInfo info = SkImageInfo::MakeN32Premul(ir.width(), ir.height(), kLine
ar_SkColorProfileType); |
59 | 59 |
60 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, pmsrc.addr32(),
pmsrc.rowBytes()))); | 60 sk_sp<SkImage> image(SkImage::MakeRasterCopy(SkPixmap(info, pmsrc.addr32(),
pmsrc.rowBytes()))); |
61 SkPaint paint; | 61 SkPaint paint; |
62 int32_t storage[300]; | 62 int32_t storage[300]; |
63 paint.setShader(image->makeShader(SkShader::kClamp_TileMode, SkShader::kClam
p_TileMode)); | 63 |
| 64 sk_sp<SkShader> shader = image->makeShader(SkShader::kRepeat_TileMode, |
| 65 SkShader::kRepeat_TileMode); |
| 66 |
64 if (useBilerp) { | 67 if (useBilerp) { |
65 paint.setFilterQuality(SkFilterQuality::kLow_SkFilterQuality); | 68 paint.setFilterQuality(SkFilterQuality::kLow_SkFilterQuality); |
66 } else { | 69 } else { |
67 paint.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality); | 70 paint.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality); |
68 } | 71 } |
| 72 paint.setShader(std::move(shader)); |
69 const SkShader::ContextRec rec(paint, *mat, nullptr, | 73 const SkShader::ContextRec rec(paint, *mat, nullptr, |
70 SkBlitter::PreferredShaderDest(pmsrc.info()))
; | 74 SkBlitter::PreferredShaderDest(pmsrc.info()))
; |
71 SkASSERT(paint.getShader()->contextSize(rec) <= sizeof(storage)); | 75 SkASSERT(paint.getShader()->contextSize(rec) <= sizeof(storage)); |
72 | 76 |
73 SkShader::Context* ctx = paint.getShader()->createContext(rec, storage); | 77 SkShader::Context* ctx = paint.getShader()->createContext(rec, storage); |
74 | 78 |
75 for (int y = 0; y < ir.height(); y++) { | 79 for (int y = 0; y < ir.height(); y++) { |
76 ctx->shadeSpan(0, y, pmdst.writable_addr32(0, y), ir.width()); | 80 ctx->shadeSpan(0, y, pmdst.writable_addr32(0, y), ir.width()); |
77 } | 81 } |
78 | 82 |
79 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr); | 83 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr); |
80 | 84 |
81 ctx->~Context(); | 85 ctx->~Context(); |
82 | |
83 } | 86 } |
84 | 87 |
85 static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM
atrix* mat, bool useBilerp) { | 88 static void draw_rect_fp(SkCanvas* canvas, const SkRect& r, SkColor c, const SkM
atrix* mat, bool useBilerp) { |
86 const SkIRect ir = r.round(); | 89 const SkIRect ir = r.round(); |
87 | 90 |
88 SkBitmap bmsrc; | 91 SkBitmap bmsrc; |
89 fill_in_bits(bmsrc, ir, c, true); | 92 fill_in_bits(bmsrc, ir, c, true); |
90 SkPixmap pmsrc; | 93 SkPixmap pmsrc; |
91 bmsrc.peekPixels(&pmsrc); | 94 bmsrc.peekPixels(&pmsrc); |
92 | 95 |
(...skipping 17 matching lines...) Expand all Loading... |
110 } | 113 } |
111 | 114 |
112 uint32_t flags = 0; | 115 uint32_t flags = 0; |
113 //if (kSRGB_SkColorProfileType == profile) { | 116 //if (kSRGB_SkColorProfileType == profile) { |
114 //flags |= SkXfermode::kDstIsSRGB_PM4fFlag; | 117 //flags |= SkXfermode::kDstIsSRGB_PM4fFlag; |
115 //} | 118 //} |
116 auto procN = SkXfermode::GetD32Proc(nullptr, flags); | 119 auto procN = SkXfermode::GetD32Proc(nullptr, flags); |
117 | 120 |
118 SkLinearBitmapPipeline pipeline{ | 121 SkLinearBitmapPipeline pipeline{ |
119 inv, filterQuality, | 122 inv, filterQuality, |
120 SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, pmsrc}; | 123 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, 1.0f, pmsrc}
; |
121 | 124 |
122 for (int y = 0; y < ir.height(); y++) { | 125 for (int y = 0; y < ir.height(); y++) { |
123 pipeline.shadeSpan4f(0, y, dstBits, ir.width()); | 126 pipeline.shadeSpan4f(0, y, dstBits, ir.width()); |
124 procN(nullptr, pmdst.writable_addr32(0, y), dstBits, ir.width(), nullptr
); | 127 procN(nullptr, pmdst.writable_addr32(0, y), dstBits, ir.width(), nullptr
); |
125 } | 128 } |
126 | 129 |
127 delete [] dstBits; | 130 delete [] dstBits; |
128 | 131 |
129 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr); | 132 canvas->drawBitmap(bmdst, r.left(), r.top(), nullptr); |
130 } | 133 } |
(...skipping 23 matching lines...) Expand all Loading... |
154 canvas->translate(20, 20); | 157 canvas->translate(20, 20); |
155 | 158 |
156 SkMatrix mi = SkMatrix::I(); | 159 SkMatrix mi = SkMatrix::I(); |
157 SkMatrix mlr; | 160 SkMatrix mlr; |
158 mlr.setScale(-1.0f, 1.0f, 20, 0.0f); | 161 mlr.setScale(-1.0f, 1.0f, 20, 0.0f); |
159 SkMatrix mt; | 162 SkMatrix mt; |
160 mt.setTranslate(8, 8); | 163 mt.setTranslate(8, 8); |
161 SkMatrix mt2; | 164 SkMatrix mt2; |
162 mt2.setTranslate(-18, -18); | 165 mt2.setTranslate(-18, -18); |
163 SkMatrix ms; | 166 SkMatrix ms; |
164 ms.setScale(2.7f, 2.7f); | 167 ms.setScale(2.7f, 2.7f, -1.5f, 0); |
165 SkMatrix ms2; | 168 SkMatrix ms2; |
166 ms2.setScale(-0.2f, 0.2f); | 169 ms2.setScale(-0.4f, 0.4f); |
167 SkMatrix mr; | 170 SkMatrix mr; |
168 mr.setRotate(10); | 171 mr.setRotate(10); |
169 | 172 |
170 const SkMatrix* mats[] = {nullptr, &mi, &mlr, &mt, &mt2, &ms, &ms2, &mr}; | 173 const SkMatrix* mats[] = {nullptr, &mi, &mlr, &mt, &mt2, &ms, &ms2, &mr}; |
171 | 174 |
172 const SkRect r = SkRect::MakeWH(W, H); | 175 const SkRect r = SkRect::MakeWH(W, H); |
173 bool useBilerp = false; | 176 bool useBilerp = false; |
174 while (true) { | 177 while (true) { |
175 canvas->save(); | 178 canvas->save(); |
176 for (auto mat : mats) { | 179 for (auto mat : mats) { |
(...skipping 15 matching lines...) Expand all Loading... |
192 } | 195 } |
193 canvas->restore(); | 196 canvas->restore(); |
194 canvas->translate(0, H + 20); | 197 canvas->translate(0, H + 20); |
195 } | 198 } |
196 canvas->restore(); | 199 canvas->restore(); |
197 canvas->translate(0, (H + 20) * SK_ARRAY_COUNT(mats)); | 200 canvas->translate(0, (H + 20) * SK_ARRAY_COUNT(mats)); |
198 if (useBilerp) break; | 201 if (useBilerp) break; |
199 useBilerp = true; | 202 useBilerp = true; |
200 } | 203 } |
201 } | 204 } |
OLD | NEW |