Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright 2014 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 8 #include "SkMaskCache.h" | |
| 9 | |
| 10 struct RRectBlurKey : public SkScaledImageCache::Key { | |
| 11 public: | |
| 12 RRectBlurKey(SkScalar sigma, const SkRRect rrect) | |
| 13 : fSigma(sigma) | |
| 14 , fRRect(rrect) { | |
| 15 this->init(sizeof(fSigma) + sizeof(fRRect)); | |
| 16 } | |
| 17 | |
| 18 SkScalar fSigma; | |
| 19 SkRRect fRRect; | |
| 20 }; | |
| 21 | |
| 22 struct RectsBlurKey : public SkScaledImageCache::Key { | |
| 23 public: | |
| 24 RectsBlurKey(SkScalar sigma, int32_t count, const SkRect rects[]) | |
| 25 : fSigma(sigma) | |
| 26 , fRecCount(count) { | |
| 27 for (int i = 0; i < count; i++) { | |
| 28 fRects[i] = rects[i]; | |
| 29 } | |
| 30 this->init(sizeof(fSigma) + sizeof(fRecCount) + sizeof(SkRect) * fRecCou nt); | |
| 31 } | |
| 32 | |
| 33 SkScalar fSigma; | |
| 34 int32_t fRecCount; | |
| 35 SkRect fRects[2]; | |
| 36 }; | |
| 37 | |
| 38 //////////////////////////////////////////////////////////////////////////////// ////////// | |
| 39 | |
| 40 SkMaskCache::ID* SkMaskCache::FindAndLock(SkScalar sigma, | |
| 41 const SkRRect rrect, | |
| 42 SkMask* result) { | |
| 43 RRectBlurKey key(sigma, rrect); | |
| 44 SkBitmap bitmap; | |
| 45 ID* cacheId = SkScaledImageCache::FindAndLock(key, &bitmap); | |
| 46 if (cacheId) { | |
| 47 SkAutoLockPixels autoLockPixels(bitmap); | |
| 48 result->fBounds.set(0, 0, bitmap.width(), bitmap.height()); | |
| 49 result->fRowBytes = result->fBounds.width(); | |
| 50 result->fFormat = SkMask::kA8_Format; | |
| 51 result->fImage = static_cast<uint8_t*>(bitmap.getPixels()); | |
| 52 } | |
| 53 | |
| 54 return cacheId; | |
| 55 } | |
| 56 | |
| 57 SkMaskCache::ID* SkMaskCache::AddAndLock(SkScalar sigma, | |
| 58 const SkRRect rrect, | |
| 59 const SkMask& mask) { | |
| 60 SkBitmap bitmap; | |
| 61 bitmap.installMaskPixels(mask); | |
|
reed1
2014/08/25 11:58:42
installMaskPixels does not copy the memory for the
qiankun
2014/08/26 08:36:33
The pixels owned by mask won't be freed in this bl
| |
| 62 RRectBlurKey key(sigma, rrect); | |
| 63 return SkScaledImageCache::AddAndLock(key, bitmap); | |
| 64 } | |
| 65 | |
| 66 //// | |
| 67 | |
| 68 SkMaskCache::ID* SkMaskCache::FindAndLock(SkScalar sigma, | |
| 69 unsigned count, | |
| 70 const SkRect rects[], | |
| 71 SkMask* result) { | |
| 72 RectsBlurKey key(sigma, count, rects); | |
| 73 SkBitmap bitmap; | |
| 74 ID* cacheId = SkScaledImageCache::FindAndLock(key, &bitmap); | |
| 75 if (cacheId) { | |
| 76 SkAutoLockPixels autoLockPixels(bitmap); | |
| 77 result->fBounds.set(0, 0, bitmap.width(), bitmap.height()); | |
| 78 result->fRowBytes = result->fBounds.width(); | |
| 79 result->fFormat = SkMask::kA8_Format; | |
| 80 result->fImage = static_cast<uint8_t*>(bitmap.getPixels()); | |
| 81 } | |
| 82 | |
| 83 return cacheId; | |
| 84 } | |
| 85 | |
| 86 SkMaskCache::ID* SkMaskCache::AddAndLock(SkScalar sigma, | |
| 87 unsigned count, | |
| 88 const SkRect rects[], | |
| 89 const SkMask& mask) { | |
| 90 SkBitmap bitmap; | |
| 91 bitmap.installMaskPixels(mask); | |
| 92 RectsBlurKey key(sigma, count, rects); | |
| 93 return SkScaledImageCache::AddAndLock(key, bitmap); | |
| 94 } | |
| 95 | |
| OLD | NEW |