| 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" |
| 11 #include "SkErrorInternals.h" | 11 #include "SkErrorInternals.h" |
| 12 #include "SkPixelRef.h" | 12 #include "SkPixelRef.h" |
| 13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
| 14 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
| 15 | 15 |
| 16 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 17 #include "effects/GrBicubicEffect.h" | 17 #include "effects/GrBicubicEffect.h" |
| 18 #include "effects/GrExtractAlphaFragmentProcessor.h" | 18 #include "effects/GrExtractAlphaFragmentProcessor.h" |
| 19 #include "effects/GrSimpleTextureEffect.h" | 19 #include "effects/GrSimpleTextureEffect.h" |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 size_t SkBitmapProcShader::ContextSize() { |
| 23 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding |
| 24 // a pointer to it. |
| 25 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); |
| 26 } |
| 27 |
| 22 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, | 28 SkBitmapProcShader::SkBitmapProcShader(const SkBitmap& src, TileMode tmx, TileMo
de tmy, |
| 23 const SkMatrix* localMatrix) | 29 const SkMatrix* localMatrix) |
| 24 : INHERITED(localMatrix) { | 30 : INHERITED(localMatrix) { |
| 25 fRawBitmap = src; | 31 fRawBitmap = src; |
| 26 fTileModeX = (uint8_t)tmx; | 32 fTileModeX = (uint8_t)tmx; |
| 27 fTileModeY = (uint8_t)tmy; | 33 fTileModeY = (uint8_t)tmy; |
| 28 } | 34 } |
| 29 | 35 |
| 30 bool SkBitmapProcShader::onIsABitmap(SkBitmap* texture, SkMatrix* texM, TileMode
xy[]) const { | 36 bool SkBitmapProcShader::onIsABitmap(SkBitmap* texture, SkMatrix* texM, TileMode
xy[]) const { |
| 31 if (texture) { | 37 if (texture) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 69 |
| 64 static bool only_scale_and_translate(const SkMatrix& matrix) { | 70 static bool only_scale_and_translate(const SkMatrix& matrix) { |
| 65 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; | 71 unsigned mask = SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask; |
| 66 return (matrix.getType() & ~mask) == 0; | 72 return (matrix.getType() & ~mask) == 0; |
| 67 } | 73 } |
| 68 | 74 |
| 69 bool SkBitmapProcShader::isOpaque() const { | 75 bool SkBitmapProcShader::isOpaque() const { |
| 70 return fRawBitmap.isOpaque(); | 76 return fRawBitmap.isOpaque(); |
| 71 } | 77 } |
| 72 | 78 |
| 73 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, vo
id* storage) const { | 79 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader, |
| 80 TileMode tmx, TileMode tmy, |
| 81 const SkBitmap& bitmap, |
| 82 const ContextRec& rec, void*
storage) { |
| 74 SkMatrix totalInverse; | 83 SkMatrix totalInverse; |
| 75 // Do this first, so we know the matrix can be inverted. | 84 // Do this first, so we know the matrix can be inverted. |
| 76 if (!this->computeTotalInverse(rec, &totalInverse)) { | 85 if (!shader.computeTotalInverse(rec, &totalInverse)) { |
| 77 return nullptr; | 86 return nullptr; |
| 78 } | 87 } |
| 79 | 88 |
| 80 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); | 89 void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext); |
| 81 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState; | 90 SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(SkBitmapProv
ider(bitmap), |
| 91 tmx, tmy); |
| 82 | 92 |
| 83 SkASSERT(state); | 93 SkASSERT(state); |
| 84 state->fTileModeX = fTileModeX; | |
| 85 state->fTileModeY = fTileModeY; | |
| 86 state->fOrigBitmap = fRawBitmap; | |
| 87 if (!state->chooseProcs(totalInverse, *rec.fPaint)) { | 94 if (!state->chooseProcs(totalInverse, *rec.fPaint)) { |
| 88 state->~SkBitmapProcState(); | 95 state->~SkBitmapProcState(); |
| 89 return nullptr; | 96 return nullptr; |
| 90 } | 97 } |
| 91 | 98 |
| 92 return new (storage) BitmapProcShaderContext(*this, rec, state); | 99 return new (storage) BitmapProcShaderContext(shader, rec, state); |
| 93 } | 100 } |
| 94 | 101 |
| 95 size_t SkBitmapProcShader::contextSize() const { | 102 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, vo
id* storage) const { |
| 96 // The SkBitmapProcState is stored outside of the context object, with the c
ontext holding | 103 return MakeContext(*this, (TileMode)fTileModeX, (TileMode)fTileModeY, fRawBi
tmap, rec, storage); |
| 97 // a pointer to it. | |
| 98 return sizeof(BitmapProcShaderContext) + sizeof(SkBitmapProcState); | |
| 99 } | 104 } |
| 100 | 105 |
| 101 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext( | 106 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext(const SkSha
der& shader, |
| 102 const SkBitmapProcShader& shader, const ContextRec& rec, SkBitmapProcSta
te* state) | 107 const Conte
xtRec& rec, |
| 108 SkBitmapPro
cState* state) |
| 103 : INHERITED(shader, rec) | 109 : INHERITED(shader, rec) |
| 104 , fState(state) | 110 , fState(state) |
| 105 { | 111 { |
| 106 const SkPixmap& pixmap = fState->fPixmap; | 112 const SkPixmap& pixmap = fState->fPixmap; |
| 107 bool isOpaque = pixmap.isOpaque(); | 113 bool isOpaque = pixmap.isOpaque(); |
| 108 | 114 |
| 109 // update fFlags | 115 // update fFlags |
| 110 uint32_t flags = 0; | 116 uint32_t flags = 0; |
| 111 if (isOpaque && (255 == this->getPaintAlpha())) { | 117 if (isOpaque && (255 == this->getPaintAlpha())) { |
| 112 flags |= kOpaqueAlpha_Flag; | 118 flags |= kOpaqueAlpha_Flag; |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matr
ix, params)); | 407 inner.reset(GrSimpleTextureEffect::Create(procDataManager, texture, matr
ix, params)); |
| 402 } | 408 } |
| 403 | 409 |
| 404 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { | 410 if (kAlpha_8_SkColorType == fRawBitmap.colorType()) { |
| 405 return SkRef(inner.get()); | 411 return SkRef(inner.get()); |
| 406 } | 412 } |
| 407 return GrExtractAlphaFragmentProcessor::Create(inner); | 413 return GrExtractAlphaFragmentProcessor::Create(inner); |
| 408 } | 414 } |
| 409 | 415 |
| 410 #endif | 416 #endif |
| OLD | NEW |