| 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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } | 70 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } |
| 71 virtual size_t bytesUsed() const SK_OVERRIDE { | 71 virtual size_t bytesUsed() const SK_OVERRIDE { |
| 72 return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes; | 72 return sizeof(fKey) + sizeof(SkShader) + fBitmapBytes; |
| 73 } | 73 } |
| 74 | 74 |
| 75 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader
) { | 75 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextShader
) { |
| 76 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec
); | 76 const BitmapShaderRec& rec = static_cast<const BitmapShaderRec&>(baseRec
); |
| 77 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>
*>(contextShader); | 77 SkAutoTUnref<SkShader>* result = reinterpret_cast<SkAutoTUnref<SkShader>
*>(contextShader); |
| 78 | 78 |
| 79 result->reset(SkRef(rec.fShader.get())); | 79 result->reset(SkRef(rec.fShader.get())); |
| 80 return true; | 80 |
| 81 SkBitmap tile; |
| 82 rec.fShader.get()->asABitmap(&tile, NULL, NULL); |
| 83 // FIXME: this doesn't protect the pixels from being discarded as soon a
s we unlock. |
| 84 // Should be handled via a pixel ref generator instead |
| 85 // (https://code.google.com/p/skia/issues/detail?id=3220). |
| 86 SkAutoLockPixels alp(tile, true); |
| 87 return tile.getPixels() != NULL; |
| 81 } | 88 } |
| 82 }; | 89 }; |
| 83 | 90 |
| 84 static bool cache_try_alloc_pixels(SkBitmap* bitmap) { | 91 static bool cache_try_alloc_pixels(SkBitmap* bitmap) { |
| 85 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); | 92 SkBitmap::Allocator* allocator = SkResourceCache::GetAllocator(); |
| 86 | 93 |
| 87 return NULL != allocator | 94 return NULL != allocator |
| 88 ? allocator->allocPixelRef(bitmap, NULL) | 95 ? allocator->allocPixelRef(bitmap, NULL) |
| 89 : bitmap->tryAllocPixels(); | 96 : bitmap->tryAllocPixels(); |
| 90 } | 97 } |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 } | 295 } |
| 289 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f
p); | 296 return bitmapShader->asFragmentProcessor(context, paint, NULL, paintColor, f
p); |
| 290 } | 297 } |
| 291 #else | 298 #else |
| 292 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa
trix*, GrColor*, | 299 bool SkPictureShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMa
trix*, GrColor*, |
| 293 GrFragmentProcessor**) const { | 300 GrFragmentProcessor**) const { |
| 294 SkDEBUGFAIL("Should not call in GPU-less build"); | 301 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 295 return false; | 302 return false; |
| 296 } | 303 } |
| 297 #endif | 304 #endif |
| OLD | NEW |