OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
9 #include "SkColorFilter.h" | 9 #include "SkColorFilter.h" |
10 #include "SkConfig8888.h" | 10 #include "SkConfig8888.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 SkDstPixelInfo dstPI; | 50 SkDstPixelInfo dstPI; |
51 dstPI.fColorType = kRGBA_8888_SkColorType; | 51 dstPI.fColorType = kRGBA_8888_SkColorType; |
52 dstPI.fAlphaType = kPremul_SkAlphaType; | 52 dstPI.fAlphaType = kPremul_SkAlphaType; |
53 dstPI.fPixels = buffer; | 53 dstPI.fPixels = buffer; |
54 dstPI.fRowBytes = count * sizeof(SkPMColor); | 54 dstPI.fRowBytes = count * sizeof(SkPMColor); |
55 | 55 |
56 SkSrcPixelInfo srcPI; | 56 SkSrcPixelInfo srcPI; |
57 srcPI.fColorType = kN32_SkColorType; | 57 srcPI.fColorType = kN32_SkColorType; |
58 srcPI.fAlphaType = kPremul_SkAlphaType; | 58 srcPI.fAlphaType = kPremul_SkAlphaType; |
59 srcPI.fPixels = ctable->lockColors(); | 59 srcPI.fPixels = ctable->readColors(); |
60 srcPI.fRowBytes = count * sizeof(SkPMColor); | 60 srcPI.fRowBytes = count * sizeof(SkPMColor); |
61 | 61 |
62 srcPI.convertPixelsTo(&dstPI, count, 1); | 62 srcPI.convertPixelsTo(&dstPI, count, 1); |
63 | 63 |
64 ctable->unlockColors(); | |
65 | |
66 // always skip a full 256 number of entries, even if we memcpy'd fewer | 64 // always skip a full 256 number of entries, even if we memcpy'd fewer |
67 dst += 256 * sizeof(GrColor); | 65 dst += 256 * sizeof(GrColor); |
68 | 66 |
69 if ((unsigned)bitmap.width() == bitmap.rowBytes()) { | 67 if ((unsigned)bitmap.width() == bitmap.rowBytes()) { |
70 memcpy(dst, bitmap.getPixels(), bitmap.getSize()); | 68 memcpy(dst, bitmap.getPixels(), bitmap.getSize()); |
71 } else { | 69 } else { |
72 // need to trim off the extra bytes per row | 70 // need to trim off the extra bytes per row |
73 size_t width = bitmap.width(); | 71 size_t width = bitmap.width(); |
74 size_t rowBytes = bitmap.rowBytes(); | 72 size_t rowBytes = bitmap.rowBytes(); |
75 const char* src = (const char*)bitmap.getPixels(); | 73 const char* src = (const char*)bitmap.getPixels(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 196 |
199 // Is it actually an ETC1 texture? | 197 // Is it actually an ETC1 texture? |
200 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { | 198 if (!ktx.isCompressedFormat(SkTextureCompressor::kETC1_Format)) { |
201 return NULL; | 199 return NULL; |
202 } | 200 } |
203 | 201 |
204 // Does the data match the dimensions of the bitmap? If not, | 202 // Does the data match the dimensions of the bitmap? If not, |
205 // then we don't know how to scale the image to match it... | 203 // then we don't know how to scale the image to match it... |
206 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { | 204 if (ktx.width() != bm.width() || ktx.height() != bm.height()) { |
207 return NULL; | 205 return NULL; |
208 } | 206 } |
209 | 207 |
210 bytes = ktx.pixelData(); | 208 bytes = ktx.pixelData(); |
211 desc.fConfig = kETC1_GrPixelConfig; | 209 desc.fConfig = kETC1_GrPixelConfig; |
212 } else { | 210 } else { |
213 return NULL; | 211 return NULL; |
214 } | 212 } |
215 | 213 |
216 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); | 214 return sk_gr_allocate_texture(ctx, cache, params, bm, desc, bytes, 0); |
217 } | 215 } |
218 #endif // SK_IGNORE_ETC1_SUPPORT | 216 #endif // SK_IGNORE_ETC1_SUPPORT |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 sm = SkXfermode::kOne_Coeff; | 472 sm = SkXfermode::kOne_Coeff; |
475 dm = SkXfermode::kZero_Coeff; | 473 dm = SkXfermode::kZero_Coeff; |
476 } | 474 } |
477 } else { | 475 } else { |
478 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) | 476 //SkDEBUGCODE(SkDebugf("Unsupported xfer mode.\n");) |
479 // Fall back to src-over | 477 // Fall back to src-over |
480 sm = SkXfermode::kOne_Coeff; | 478 sm = SkXfermode::kOne_Coeff; |
481 dm = SkXfermode::kISA_Coeff; | 479 dm = SkXfermode::kISA_Coeff; |
482 } | 480 } |
483 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); | 481 grPaint->setBlendFunc(sk_blend_to_grblend(sm), sk_blend_to_grblend(dm)); |
484 | 482 |
485 //set the color of the paint to the one of the parameter | 483 //set the color of the paint to the one of the parameter |
486 grPaint->setColor(paintColor); | 484 grPaint->setColor(paintColor); |
487 | 485 |
488 SkColorFilter* colorFilter = skPaint.getColorFilter(); | 486 SkColorFilter* colorFilter = skPaint.getColorFilter(); |
489 if (colorFilter) { | 487 if (colorFilter) { |
490 // if the source color is a constant then apply the filter here once rat
her than per pixel | 488 // if the source color is a constant then apply the filter here once rat
her than per pixel |
491 // in a shader. | 489 // in a shader. |
492 if (constantColor) { | 490 if (constantColor) { |
493 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); | 491 SkColor filtered = colorFilter->filterColor(skPaint.getColor()); |
494 grPaint->setColor(SkColor2GrColor(filtered)); | 492 grPaint->setColor(SkColor2GrColor(filtered)); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { | 571 if (shader->asFragmentProcessor(context, skPaint, NULL, &paintColor, &fp
) && fp) { |
574 grPaint->addColorProcessor(fp)->unref(); | 572 grPaint->addColorProcessor(fp)->unref(); |
575 constantColor = false; | 573 constantColor = false; |
576 } | 574 } |
577 } | 575 } |
578 | 576 |
579 // The grcolor is automatically set when calling asFragmentProcessor. | 577 // The grcolor is automatically set when calling asFragmentProcessor. |
580 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 578 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
581 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 579 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
582 } | 580 } |
OLD | NEW |