| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapProcShader.h" | 8 #include "SkBitmapProcShader.h" |
| 9 #include "SkBitmapProcState.h" | 9 #include "SkBitmapProcState.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 | 73 |
| 74 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, vo
id* storage) const { | 74 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, vo
id* storage) const { |
| 75 SkMatrix totalInverse; | 75 SkMatrix totalInverse; |
| 76 // Do this first, so we know the matrix can be inverted. | 76 // Do this first, so we know the matrix can be inverted. |
| 77 if (!this->computeTotalInverse(rec, &totalInverse)) { | 77 if (!this->computeTotalInverse(rec, &totalInverse)) { |
| 78 return NULL; | 78 return NULL; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); | 81 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); |
| 82 SkBitmapProcState* state = SkNEW_PLACEMENT(stateStorage, SkBitmapProcState); | 82 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState; |
| 83 | 83 |
| 84 SkASSERT(state); | 84 SkASSERT(state); |
| 85 state->fTileModeX = fTileModeX; | 85 state->fTileModeX = fTileModeX; |
| 86 state->fTileModeY = fTileModeY; | 86 state->fTileModeY = fTileModeY; |
| 87 state->fOrigBitmap = fRawBitmap; | 87 state->fOrigBitmap = fRawBitmap; |
| 88 if (!state->chooseProcs(totalInverse, *rec.fPaint)) { | 88 if (!state->chooseProcs(totalInverse, *rec.fPaint)) { |
| 89 state->~SkBitmapProcState(); | 89 state->~SkBitmapProcState(); |
| 90 return NULL; | 90 return NULL; |
| 91 } | 91 } |
| 92 | 92 |
| 93 return SkNEW_PLACEMENT_ARGS(storage, BitmapProcShaderContext, (*this, rec, s
tate)); | 93 return new (storage) BitmapProcShaderContext(*this, rec, state); |
| 94 } | 94 } |
| 95 | 95 |
| 96 size_t SkBitmapProcShader::contextSize() const { | 96 size_t SkBitmapProcShader::contextSize() const { |
| 97 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding | 97 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding |
| 98 // a pointer to it. | 98 // a pointer to it. |
| 99 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); | 99 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); |
| 100 } | 100 } |
| 101 | 101 |
| 102 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( | 102 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( |
| 103 const SkBitmapProcShader& shader, const ContextRec& rec, SkBitmapProcSta
te* state) | 103 const SkBitmapProcShader& shader, const ContextRec& rec, SkBitmapProcSta
te* state) |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 return bm.width() > kMaxSize || bm.height() > kMaxSize; | 295 return bm.width() > kMaxSize || bm.height() > kMaxSize; |
| 296 } | 296 } |
| 297 | 297 |
| 298 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, | 298 SkShader* SkCreateBitmapShader(const SkBitmap& src, SkShader::TileMode tmx, |
| 299 SkShader::TileMode tmy, const SkMatrix* localMatr
ix, | 299 SkShader::TileMode tmy, const SkMatrix* localMatr
ix, |
| 300 SkTBlitterAllocator* allocator) { | 300 SkTBlitterAllocator* allocator) { |
| 301 SkShader* shader; | 301 SkShader* shader; |
| 302 SkColor color; | 302 SkColor color; |
| 303 if (src.isNull() || bitmap_is_too_big(src)) { | 303 if (src.isNull() || bitmap_is_too_big(src)) { |
| 304 if (NULL == allocator) { | 304 if (NULL == allocator) { |
| 305 shader = SkNEW(SkEmptyShader); | 305 shader = new SkEmptyShader; |
| 306 } else { | 306 } else { |
| 307 shader = allocator->createT<SkEmptyShader>(); | 307 shader = allocator->createT<SkEmptyShader>(); |
| 308 } | 308 } |
| 309 } else if (can_use_color_shader(src, &color)) { | 309 } else if (can_use_color_shader(src, &color)) { |
| 310 if (NULL == allocator) { | 310 if (NULL == allocator) { |
| 311 shader = SkNEW_ARGS(SkColorShader, (color)); | 311 shader = new SkColorShader(color); |
| 312 } else { | 312 } else { |
| 313 shader = allocator->createT<SkColorShader>(color); | 313 shader = allocator->createT<SkColorShader>(color); |
| 314 } | 314 } |
| 315 } else { | 315 } else { |
| 316 if (NULL == allocator) { | 316 if (NULL == allocator) { |
| 317 shader = SkNEW_ARGS(SkBitmapProcShader, (src, tmx, tmy, localMatrix)
); | 317 shader = new SkBitmapProcShader(src, tmx, tmy, localMatrix); |
| 318 } else { | 318 } else { |
| 319 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); | 319 shader = allocator->createT<SkBitmapProcShader>(src, tmx, tmy, local
Matrix); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 return shader; | 322 return shader; |
| 323 } | 323 } |
| 324 | 324 |
| 325 /////////////////////////////////////////////////////////////////////////////// | 325 /////////////////////////////////////////////////////////////////////////////// |
| 326 | 326 |
| 327 #ifndef SK_IGNORE_TO_STRING | 327 #ifndef SK_IGNORE_TO_STRING |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 #else | 412 #else |
| 413 | 413 |
| 414 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S
kMatrix&, | 414 bool SkBitmapProcShader::asFragmentProcessor(GrContext*, const SkPaint&, const S
kMatrix&, |
| 415 const SkMatrix*, GrColor*, GrProces
sorDataManager*, | 415 const SkMatrix*, GrColor*, GrProces
sorDataManager*, |
| 416 GrFragmentProcessor**) const { | 416 GrFragmentProcessor**) const { |
| 417 SkDEBUGFAIL("Should not call in GPU-less build"); | 417 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 418 return false; | 418 return false; |
| 419 } | 419 } |
| 420 | 420 |
| 421 #endif | 421 #endif |
| OLD | NEW |