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

Side by Side Diff: src/effects/SkTableColorFilter.cpp

Issue 968993004: add virtuals to optimize composing colorfilters (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix param warning Created 5 years, 9 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 | « src/effects/SkColorMatrixFilter.cpp ('k') | 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
1 1
2 #include "SkBitmap.h" 2 #include "SkBitmap.h"
3 #include "SkTableColorFilter.h" 3 #include "SkTableColorFilter.h"
4 #include "SkColorPriv.h" 4 #include "SkColorPriv.h"
5 #include "SkReadBuffer.h" 5 #include "SkReadBuffer.h"
6 #include "SkWriteBuffer.h" 6 #include "SkWriteBuffer.h"
7 #include "SkUnPreMultiply.h" 7 #include "SkUnPreMultiply.h"
8 #include "SkString.h" 8 #include "SkString.h"
9 9
10 class SkTable_ColorFilter : public SkColorFilter { 10 class SkTable_ColorFilter : public SkColorFilter {
(...skipping 23 matching lines...) Expand all
34 memcpy(dst, tableB, 256); 34 memcpy(dst, tableB, 256);
35 fFlags |= kB_Flag; 35 fFlags |= kB_Flag;
36 } 36 }
37 } 37 }
38 38
39 virtual ~SkTable_ColorFilter() { 39 virtual ~SkTable_ColorFilter() {
40 SkDELETE(fBitmap); 40 SkDELETE(fBitmap);
41 } 41 }
42 42
43 bool asComponentTable(SkBitmap* table) const SK_OVERRIDE; 43 bool asComponentTable(SkBitmap* table) const SK_OVERRIDE;
44 SkColorFilter* newComposed(const SkColorFilter* inner) const SK_OVERRIDE;
44 45
45 #if SK_SUPPORT_GPU 46 #if SK_SUPPORT_GPU
46 GrFragmentProcessor* asFragmentProcessor(GrContext* context) const SK_OVERRI DE; 47 GrFragmentProcessor* asFragmentProcessor(GrContext* context) const SK_OVERRI DE;
47 #endif 48 #endif
48 49
49 virtual void filterSpan(const SkPMColor src[], int count, 50 void filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const SK_ OVERRIDE;
50 SkPMColor dst[]) const SK_OVERRIDE;
51 51
52 SK_TO_STRING_OVERRIDE() 52 SK_TO_STRING_OVERRIDE()
53 53
54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter) 54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkTable_ColorFilter)
55 55
56 enum { 56 enum {
57 kA_Flag = 1 << 0, 57 kA_Flag = 1 << 0,
58 kR_Flag = 1 << 1, 58 kR_Flag = 1 << 1,
59 kG_Flag = 1 << 2, 59 kG_Flag = 1 << 2,
60 kB_Flag = 1 << 3, 60 kB_Flag = 1 << 3,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 102 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
103 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 103 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
104 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 104 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
105 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, 105 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
106 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 106 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
107 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 107 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
108 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 108 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
109 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF 109 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
110 }; 110 };
111 111
112 void SkTable_ColorFilter::filterSpan(const SkPMColor src[], int count, 112 void SkTable_ColorFilter::filterSpan(const SkPMColor src[], int count, SkPMColor dst[]) const {
113 SkPMColor dst[]) const {
114 const uint8_t* table = fStorage; 113 const uint8_t* table = fStorage;
115 const uint8_t* tableA = gIdentityTable; 114 const uint8_t* tableA = gIdentityTable;
116 const uint8_t* tableR = gIdentityTable; 115 const uint8_t* tableR = gIdentityTable;
117 const uint8_t* tableG = gIdentityTable; 116 const uint8_t* tableG = gIdentityTable;
118 const uint8_t* tableB = gIdentityTable; 117 const uint8_t* tableB = gIdentityTable;
119 if (fFlags & kA_Flag) { 118 if (fFlags & kA_Flag) {
120 tableA = table; table += 256; 119 tableA = table; table += 256;
121 } 120 }
122 if (fFlags & kR_Flag) { 121 if (fFlags & kR_Flag) {
123 tableR = table; table += 256; 122 tableR = table; table += 256;
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 266 }
268 bitmapPixels += 256; 267 bitmapPixels += 256;
269 } 268 }
270 fBitmap = bmp; 269 fBitmap = bmp;
271 } 270 }
272 *table = *fBitmap; 271 *table = *fBitmap;
273 } 272 }
274 return true; 273 return true;
275 } 274 }
276 275
276 // Combines the two lookup tables so that making a lookup using res[] has
277 // the same effect as making a lookup through inner[] then outer[].
278 static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin t8_t inner[256]) {
279 for (int i = 0; i < 256; i++) {
280 res[i] = outer[inner[i]];
281 }
282 }
283
284 SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter ) const {
285 SkBitmap innerBM;
286 if (!innerFilter->asComponentTable(&innerBM)) {
287 return NULL;
288 }
289
290 innerBM.lockPixels();
291 if (NULL == innerBM.getPixels()) {
292 return NULL;
293 }
294
295 const uint8_t* table = fStorage;
296 const uint8_t* tableA = gIdentityTable;
297 const uint8_t* tableR = gIdentityTable;
298 const uint8_t* tableG = gIdentityTable;
299 const uint8_t* tableB = gIdentityTable;
300 if (fFlags & kA_Flag) {
301 tableA = table; table += 256;
302 }
303 if (fFlags & kR_Flag) {
304 tableR = table; table += 256;
305 }
306 if (fFlags & kG_Flag) {
307 tableG = table; table += 256;
308 }
309 if (fFlags & kB_Flag) {
310 tableB = table;
311 }
312
313 uint8_t concatA[256];
314 uint8_t concatR[256];
315 uint8_t concatG[256];
316 uint8_t concatB[256];
317
318 combine_tables(concatA, tableA, innerBM.getAddr8(0, 0));
319 combine_tables(concatR, tableR, innerBM.getAddr8(0, 1));
320 combine_tables(concatG, tableG, innerBM.getAddr8(0, 2));
321 combine_tables(concatB, tableB, innerBM.getAddr8(0, 3));
322
323 return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB);
324 }
325
277 #if SK_SUPPORT_GPU 326 #if SK_SUPPORT_GPU
278 327
279 #include "GrFragmentProcessor.h" 328 #include "GrFragmentProcessor.h"
280 #include "GrInvariantOutput.h" 329 #include "GrInvariantOutput.h"
281 #include "SkGr.h" 330 #include "SkGr.h"
282 #include "effects/GrTextureStripAtlas.h" 331 #include "effects/GrTextureStripAtlas.h"
283 #include "gl/GrGLProcessor.h" 332 #include "gl/GrGLProcessor.h"
284 #include "gl/builders/GrGLProgramBuilder.h" 333 #include "gl/builders/GrGLProgramBuilder.h"
285 334
286 class ColorTableEffect : public GrFragmentProcessor { 335 class ColorTableEffect : public GrFragmentProcessor {
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256], 598 SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256],
550 const uint8_t tableR[256], 599 const uint8_t tableR[256],
551 const uint8_t tableG[256], 600 const uint8_t tableG[256],
552 const uint8_t tableB[256]) { 601 const uint8_t tableB[256]) {
553 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB)); 602 return SkNEW_ARGS(SkTable_ColorFilter, (tableA, tableR, tableG, tableB));
554 } 603 }
555 604
556 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter) 605 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
557 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter) 606 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkTable_ColorFilter)
558 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 607 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkColorMatrixFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698