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 "SkImage.h" | 13 #include "SkImage.h" |
| 14 #include "SkImageShader.h" |
14 #include "SkMatrixUtils.h" | 15 #include "SkMatrixUtils.h" |
15 #include "SkPicture.h" | 16 #include "SkPicture.h" |
16 #include "SkReadBuffer.h" | 17 #include "SkReadBuffer.h" |
17 #include "SkResourceCache.h" | 18 #include "SkResourceCache.h" |
18 | 19 |
19 #if SK_SUPPORT_GPU | 20 #if SK_SUPPORT_GPU |
20 #include "GrContext.h" | 21 #include "GrContext.h" |
21 #include "GrCaps.h" | 22 #include "GrCaps.h" |
22 #endif | 23 #endif |
23 | 24 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 uint32_t fPictureID; | 57 uint32_t fPictureID; |
57 SkRect fTile; | 58 SkRect fTile; |
58 SkShader::TileMode fTmx, fTmy; | 59 SkShader::TileMode fTmx, fTmy; |
59 SkSize fScale; | 60 SkSize fScale; |
60 SkScalar fLocalMatrixStorage[9]; | 61 SkScalar fLocalMatrixStorage[9]; |
61 | 62 |
62 SkDEBUGCODE(uint32_t fEndOfStruct;) | 63 SkDEBUGCODE(uint32_t fEndOfStruct;) |
63 }; | 64 }; |
64 | 65 |
65 struct BitmapShaderRec : public SkResourceCache::Rec { | 66 struct BitmapShaderRec : public SkResourceCache::Rec { |
66 BitmapShaderRec(const BitmapShaderKey& key, SkShader* tileShader, size_t bit
mapBytes) | 67 BitmapShaderRec(const BitmapShaderKey& key, SkShader* tileShader) |
67 : fKey(key) | 68 : fKey(key) |
68 , fShader(SkRef(tileShader)) | 69 , fShader(SkRef(tileShader)) {} |
69 , fBitmapBytes(bitmapBytes) {} | |
70 | 70 |
71 BitmapShaderKey fKey; | 71 BitmapShaderKey fKey; |
72 SkAutoTUnref<SkShader> fShader; | 72 SkAutoTUnref<SkShader> fShader; |
73 size_t fBitmapBytes; | 73 size_t fBitmapBytes; |
74 | 74 |
75 const Key& getKey() const override { return fKey; } | 75 const Key& getKey() const override { return fKey; } |
76 size_t bytesUsed() const override { | 76 size_t bytesUsed() const override { |
77 return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes; | 77 // Just the record overhead -- the actual pixels are accounted by SkImag
eCacherator. |
| 78 return sizeof(fKey) + sizeof(SkImageShader); |
78 } | 79 } |
79 const char* getCategory() const override { return "bitmap-shader"; } | 80 const char* getCategory() const override { return "bitmap-shader"; } |
80 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur
n nullptr; } | 81 SkDiscardableMemory* diagnostic_only_getDiscardable() const override { retur
n nullptr; } |
81 | 82 |
82 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader
) { | 83 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader
) { |
83 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec
); | 84 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec
); |
84 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>
*>(contextShader); | 85 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>
*>(contextShader); |
85 | 86 |
86 result->reset(SkRef(rec.fShader.get())); | 87 result->reset(SkRef(rec.fShader.get())); |
87 | 88 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 sk_sp<SkImage> tileImage( | 227 sk_sp<SkImage> tileImage( |
227 SkImage::MakeFromPicture(fPicture, tileSize, &tileMatrix, nullptr)); | 228 SkImage::MakeFromPicture(fPicture, tileSize, &tileMatrix, nullptr)); |
228 if (!tileImage) { | 229 if (!tileImage) { |
229 return nullptr; | 230 return nullptr; |
230 } | 231 } |
231 | 232 |
232 SkMatrix shaderMatrix = this->getLocalMatrix(); | 233 SkMatrix shaderMatrix = this->getLocalMatrix(); |
233 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); | 234 shaderMatrix.preScale(1 / tileScale.width(), 1 / tileScale.height()); |
234 tileShader = tileImage->makeShader(fTmx, fTmy, &shaderMatrix); | 235 tileShader = tileImage->makeShader(fTmx, fTmy, &shaderMatrix); |
235 | 236 |
236 const SkImageInfo tileInfo = SkImageInfo::MakeN32Premul(tileSize); | 237 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get())); |
237 SkResourceCache::Add(new BitmapShaderRec(key, tileShader.get(), | |
238 tileInfo.getSafeSize(tileInfo.m
inRowBytes()))); | |
239 } | 238 } |
240 | 239 |
241 return tileShader; | 240 return tileShader; |
242 } | 241 } |
243 | 242 |
244 size_t SkPictureShader::onContextSize(const ContextRec&) const { | 243 size_t SkPictureShader::onContextSize(const ContextRec&) const { |
245 return sizeof(PictureShaderContext); | 244 return sizeof(PictureShaderContext); |
246 } | 245 } |
247 | 246 |
248 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { | 247 SkShader::Context* SkPictureShader::onCreateContext(const ContextRec& rec, void*
storage) const { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 sk_sp<SkShader> bitmapShader(this->refBitmapShader(*args.fViewMatrix, args.f
LocalMatrix, | 325 sk_sp<SkShader> bitmapShader(this->refBitmapShader(*args.fViewMatrix, args.f
LocalMatrix, |
327 maxTextureSize)); | 326 maxTextureSize)); |
328 if (!bitmapShader) { | 327 if (!bitmapShader) { |
329 return nullptr; | 328 return nullptr; |
330 } | 329 } |
331 return bitmapShader->asFragmentProcessor(SkShader::AsFPArgs( | 330 return bitmapShader->asFragmentProcessor(SkShader::AsFPArgs( |
332 args.fContext, args.fViewMatrix, nullptr, args.fFilterQuality, args.fDst
ColorSpace, | 331 args.fContext, args.fViewMatrix, nullptr, args.fFilterQuality, args.fDst
ColorSpace, |
333 args.fGammaTreatment)); | 332 args.fGammaTreatment)); |
334 } | 333 } |
335 #endif | 334 #endif |
OLD | NEW |