| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "SkColorPriv.h" | 8 #include "SkColorPriv.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| 11 #include "SkPixelRef.h" | 11 #include "SkPixelRef.h" |
| 12 #include "SkErrorInternals.h" | 12 #include "SkErrorInternals.h" |
| 13 #include "SkBitmapProcShader.h" | 13 #include "SkBitmapProcShader.h" |
| 14 | 14 |
| 15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 16 #include "effects/GrSimpleTextureEffect.h" | 16 #include "effects/GrSimpleTextureEffect.h" |
| 17 #include "effects/GrBicubicEffect.h" | 17 #include "effects/GrBicubicEffect.h" |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 bool SkBitmapProcShader::CanDo(const SkBitmap& bm, TileMode tx, TileMode ty) { | |
| 21 switch (bm.colorType()) { | |
| 22 case kAlpha_8_SkColorType: | |
| 23 case kRGB_565_SkColorType: | |
| 24 case kIndex_8_SkColorType: | |
| 25 case kN32_SkColorType: | |
| 26 // if (tx == ty && (kClamp_TileMode == tx || kRepeat_TileMode == tx)) | |
| 27 return true; | |
| 28 default: | |
| 29 break; | |
| 30 } | |
| 31 return false; | |
| 32 } | |
| 33 | |
| 34 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, | 20 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, |
| 35 const SkMatrix* localMatrix) | 21 const SkMatrix* localMatrix) |
| 36 : INHERITED(localMatrix) { | 22 : INHERITED(localMatrix) { |
| 37 fRawBitmap = src; | 23 fRawBitmap = src; |
| 38 fTileModeX = (uint8_t)tmx; | 24 fTileModeX = (uint8_t)tmx; |
| 39 fTileModeY = (uint8_t)tmy; | 25 fTileModeY = (uint8_t)tmy; |
| 40 } | 26 } |
| 41 | 27 |
| 42 SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture, | 28 SkShader::BitmapType SkBitmapProcShader::asABitmap(SkBitmap* texture, |
| 43 SkMatrix* texM, | 29 SkMatrix* texM, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 246 } |
| 261 | 247 |
| 262 /////////////////////////////////////////////////////////////////////////////// | 248 /////////////////////////////////////////////////////////////////////////////// |
| 263 | 249 |
| 264 #include "SkUnPreMultiply.h" | 250 #include "SkUnPreMultiply.h" |
| 265 #include "SkColorShader.h" | 251 #include "SkColorShader.h" |
| 266 #include "SkEmptyShader.h" | 252 #include "SkEmptyShader.h" |
| 267 | 253 |
| 268 // returns true and set color if the bitmap can be drawn as a single color | 254 // returns true and set color if the bitmap can be drawn as a single color |
| 269 // (for efficiency) | 255 // (for efficiency) |
| 270 static bool canUseColorShader(const SkBitmap& bm, SkColor* color) { | 256 static bool can_use_color_shader(const SkBitmap& bm, SkColor* color) { |
| 271 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 257 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 272 // HWUI does not support color shaders (see b/22390304) | 258 // HWUI does not support color shaders (see b/22390304) |
| 273 return false; | 259 return false; |
| 274 #endif | 260 #endif |
| 275 | 261 |
| 276 if (1 != bm.width() || 1 != bm.height()) { | 262 if (1 != bm.width() || 1 != bm.height()) { |
| 277 return false; | 263 return false; |
| 278 } | 264 } |
| 279 | 265 |
| 280 SkAutoLockPixels alp(bm); | 266 SkAutoLockPixels alp(bm); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 291 return true; | 277 return true; |
| 292 case kIndex_8_SkColorType: | 278 case kIndex_8_SkColorType: |
| 293 *color = SkUnPreMultiply::PMColorToColor(bm.getIndex8Color(0, 0)); | 279 *color = SkUnPreMultiply::PMColorToColor(bm.getIndex8Color(0, 0)); |
| 294 return true; | 280 return true; |
| 295 default: // just skip the other configs for now | 281 default: // just skip the other configs for now |
| 296 break; | 282 break; |
| 297 } | 283 } |
| 298 return false; | 284 return false; |
| 299 } | 285 } |
| 300 | 286 |
| 301 static bool bitmapIsTooBig(const SkBitmap& bm) { | 287 static bool bitmap_is_too_big(const SkBitmap& bm) { |
| 302 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it | 288 // SkBitmapProcShader stores bitmap coordinates in a 16bit buffer, as it |
| 303 // communicates between its matrix-proc and its sampler-proc. Until we can | 289 // communicates between its matrix-proc and its sampler-proc. Until we can |
| 304 // widen that, we have to reject bitmaps that are larger. | 290 // widen that, we have to reject bitmaps that are larger. |
| 305 // | 291 // |
| 306 const int maxSize = 65535; | 292 static const int kMaxSize = 65535; |
| 307 | 293 |
| 308 return bm.width() > maxSize || bm.height() > maxSize; | 294 return bm.width() > kMaxSize || bm.height() > kMaxSize; |
| 309 } | 295 } |
| 310 | 296 |
| 311 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, | 297 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, |
| 312 SkShader::TileMode tmy, const SkMatrix* localMatr
ix, | 298 SkShader::TileMode tmy, const SkMatrix* localMatr
ix, |
| 313 SkTBlitterAllocator* allocator) { | 299 SkTBlitterAllocator* allocator) { |
| 314 SkShader* shader; | 300 SkShader* shader; |
| 315 SkColor color; | 301 SkColor color; |
| 316 if (src.isNull() || bitmapIsTooBig(src)) { | 302 if (src.isNull() || bitmap_is_too_big(src)) { |
| 317 if (NULL == allocator) { | 303 if (NULL == allocator) { |
| 318 shader = SkNEW(SkEmptyShader); | 304 shader = SkNEW(SkEmptyShader); |
| 319 } else { | 305 } else { |
| 320 shader = allocator->createT<SkEmptyShader>(); | 306 shader = allocator->createT<SkEmptyShader>(); |
| 321 } | 307 } |
| 322 } | 308 } else if (can_use_color_shader(src, &color)) { |
| 323 else if (canUseColorShader(src, &color)) { | |
| 324 if (NULL == allocator) { | 309 if (NULL == allocator) { |
| 325 shader = SkNEW_ARGS(SkColorShader, (color)); | 310 shader = SkNEW_ARGS(SkColorShader, (color)); |
| 326 } else { | 311 } else { |
| 327 shader = allocator->createT<SkColorShader>(color); | 312 shader = allocator->createT<SkColorShader>(color); |
| 328 } | 313 } |
| 329 } else { | 314 } else { |
| 330 if (NULL == allocator) { | 315 if (NULL == allocator) { |
| 331 shader = SkNEW_ARGS(SkBitmapProcShader, (src, tmx, tmy, localMatrix)
); | 316 shader = SkNEW_ARGS(SkBitmapProcShader, (src, tmx, tmy, localMatrix)
); |
| 332 } else { | 317 } else { |
| 333 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); | 318 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 #else | 442 #else |
| 458 | 443 |
| 459 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S
kMatrix&, | 444 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S
kMatrix&, |
| 460 const SkMatrix*, GrColor*, GrProces
sorDataManager*, | 445 const SkMatrix*, GrColor*, GrProces
sorDataManager*, |
| 461 GrFragmentProcessor**) const { | 446 GrFragmentProcessor**) const { |
| 462 SkDEBUGFAIL("Should not call in GPU-less build"); | 447 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 463 return false; | 448 return false; |
| 464 } | 449 } |
| 465 | 450 |
| 466 #endif | 451 #endif |
| OLD | NEW |