Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkPictureShader.h" | 8 #include "SkPictureShader.h" |
| 9 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| 11 #include "SkBitmapProcShader.h" | 11 #include "SkBitmapProcShader.h" |
| 12 #include "SkCanvas.h" | 12 #include "SkCanvas.h" |
| 13 #include "SkMatrixUtils.h" | 13 #include "SkMatrixUtils.h" |
| 14 #include "SkPicture.h" | 14 #include "SkPicture.h" |
| 15 #include "SkReadBuffer.h" | 15 #include "SkReadBuffer.h" |
| 16 #include "SkResourceCache.h" | 16 #include "SkResourceCache.h" |
| 17 #include "SkTypes.h" | |
| 17 | 18 |
| 18 #if SK_SUPPORT_GPU | 19 #if SK_SUPPORT_GPU |
| 19 #include "GrContext.h" | 20 #include "GrContext.h" |
| 20 #endif | 21 #endif |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 static unsigned gBitmapSkaderKeyNamespaceLabel; | 24 static unsigned gBitmapSkaderKeyNamespaceLabel; |
| 24 | 25 |
| 25 struct BitmapShaderKey : public SkResourceCache::Key { | 26 struct BitmapShaderKey : public SkResourceCache::Key { |
| 26 public: | 27 public: |
| 27 BitmapShaderKey(uint32_t pictureID, | 28 BitmapShaderKey(uint32_t pictureID, |
| 28 const SkRect& tile, | 29 const SkRect& tile, |
| 29 SkShader::TileMode tmx, | 30 SkShader::TileMode tmx, |
| 30 SkShader::TileMode tmy, | 31 SkShader::TileMode tmy, |
| 31 const SkSize& scale, | 32 const SkSize& scale, |
| 32 const SkMatrix& localMatrix) | 33 const SkMatrix& localMatrix) |
| 33 : fPictureID(pictureID) | 34 : fPictureID(pictureID) |
| 34 , fTile(tile) | 35 , fTile(tile) |
| 35 , fTmx(tmx) | 36 , fTmx(tmx) |
| 36 , fTmy(tmy) | 37 , fTmy(tmy) |
| 37 , fScale(scale) | 38 , fScale(scale) { |
| 38 , fLocalMatrix(localMatrix) { | 39 |
| 40 size_t matrixSize = localMatrix.writeToMemory(fLocalMatrixStorage); | |
| 41 SkASSERT(matrixSize <= sizeof(fLocalMatrixStorage)); | |
| 42 sk_bzero(fLocalMatrixStorage + matrixSize, sizeof(fLocalMatrixStorage) - matrixSize); | |
| 39 | 43 |
| 40 static const size_t keySize = sizeof(fPictureID) + | 44 static const size_t keySize = sizeof(fPictureID) + |
| 41 sizeof(fTile) + | 45 sizeof(fTile) + |
| 42 sizeof(fTmx) + sizeof(fTmy) + | 46 sizeof(fTmx) + sizeof(fTmy) + |
| 43 sizeof(fScale) + | 47 sizeof(fScale) + |
| 44 sizeof(fLocalMatrix); | 48 sizeof(fLocalMatrixStorage); |
| 45 // This better be packed. | 49 // This better be packed. |
| 46 SkASSERT(sizeof(uint32_t) * (&fEndOfStruct - &fPictureID) == keySize); | 50 SkASSERT(sizeof(uint32_t) * (&fEndOfStruct - &fPictureID) == keySize); |
| 47 this->init(&gBitmapSkaderKeyNamespaceLabel, keySize); | 51 this->init(&gBitmapSkaderKeyNamespaceLabel, keySize); |
| 48 } | 52 } |
| 49 | 53 |
| 50 private: | 54 private: |
| 51 uint32_t fPictureID; | 55 uint32_t fPictureID; |
| 52 SkRect fTile; | 56 SkRect fTile; |
| 53 SkShader::TileMode fTmx, fTmy; | 57 SkShader::TileMode fTmx, fTmy; |
| 54 SkSize fScale; | 58 SkSize fScale; |
| 55 SkMatrix fLocalMatrix; | 59 uint8_t fLocalMatrixStorage[SkMatrix::kMaxFlattenSize]; |
|
mtklein
2014/12/10 19:52:47
Let's be even more explicit? This actually includ
f(malita)
2014/12/10 20:03:29
Done.
| |
| 56 | 60 |
| 57 SkDEBUGCODE(uint32_t fEndOfStruct;) | 61 SkDEBUGCODE(uint32_t fEndOfStruct;) |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 struct BitmapShaderRec : public SkResourceCache::Rec { | 64 struct BitmapShaderRec : public SkResourceCache::Rec { |
| 61 BitmapShaderRec(const BitmapShaderKey& key, SkShader* tileShader, size_t bit mapBytes) | 65 BitmapShaderRec(const BitmapShaderKey& key, SkShader* tileShader, size_t bit mapBytes) |
| 62 : fKey(key) | 66 : fKey(key) |
| 63 , fShader(SkRef(tileShader)) | 67 , fShader(SkRef(tileShader)) |
| 64 , fBitmapBytes(bitmapBytes) {} | 68 , fBitmapBytes(bitmapBytes) {} |
| 65 | 69 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 292 } |
| 289 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f p); | 293 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f p); |
| 290 } | 294 } |
| 291 #else | 295 #else |
| 292 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix*, GrColor*, | 296 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa trix*, GrColor*, |
| 293 GrFragmentProcessor**) const { | 297 GrFragmentProcessor**) const { |
| 294 SkDEBUGFAIL("Should not call in GPU-less build"); | 298 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 295 return false; | 299 return false; |
| 296 } | 300 } |
| 297 #endif | 301 #endif |
| OLD | NEW |