Chromium Code Reviews| Index: src/core/SkMaskCache.cpp |
| diff --git a/src/core/SkMaskCache.cpp b/src/core/SkMaskCache.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..29c91b1abcd66003629425dd33b3a452cb735e54 |
| --- /dev/null |
| +++ b/src/core/SkMaskCache.cpp |
| @@ -0,0 +1,95 @@ |
| +/* |
| + * Copyright 2014 Google Inc. |
| + * |
| + * Use of this source code is governed by a BSD-style license that can be |
| + * found in the LICENSE file. |
| + */ |
| + |
| +#include "SkMaskCache.h" |
| + |
| +struct RRectBlurKey : public SkScaledImageCache::Key { |
| +public: |
| + RRectBlurKey(SkScalar sigma, const SkRRect rrect) |
| + : fSigma(sigma) |
| + , fRRect(rrect) { |
| + this->init(sizeof(fSigma) + sizeof(fRRect)); |
| + } |
| + |
| + SkScalar fSigma; |
| + SkRRect fRRect; |
| +}; |
| + |
| +struct RectsBlurKey : public SkScaledImageCache::Key { |
| +public: |
| + RectsBlurKey(SkScalar sigma, int32_t count, const SkRect rects[]) |
| + : fSigma(sigma) |
| + , fRecCount(count) { |
| + for (int i = 0; i < count; i++) { |
| + fRects[i] = rects[i]; |
| + } |
| + this->init(sizeof(fSigma) + sizeof(fRecCount) + sizeof(SkRect) * fRecCount); |
| + } |
| + |
| + SkScalar fSigma; |
| + int32_t fRecCount; |
| + SkRect fRects[2]; |
| +}; |
| + |
| +////////////////////////////////////////////////////////////////////////////////////////// |
| + |
| +SkMaskCache::ID* SkMaskCache::FindAndLock(SkScalar sigma, |
| + const SkRRect rrect, |
| + SkMask* result) { |
| + RRectBlurKey key(sigma, rrect); |
| + SkBitmap bitmap; |
| + ID* cacheId = SkScaledImageCache::FindAndLock(key, &bitmap); |
| + if (cacheId) { |
| + SkAutoLockPixels autoLockPixels(bitmap); |
| + result->fBounds.set(0, 0, bitmap.width(), bitmap.height()); |
| + result->fRowBytes = result->fBounds.width(); |
| + result->fFormat = SkMask::kA8_Format; |
| + result->fImage = static_cast<uint8_t*>(bitmap.getPixels()); |
| + } |
| + |
| + return cacheId; |
| +} |
| + |
| +SkMaskCache::ID* SkMaskCache::AddAndLock(SkScalar sigma, |
| + const SkRRect rrect, |
| + const SkMask& mask) { |
| + SkBitmap bitmap; |
| + 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
|
| + RRectBlurKey key(sigma, rrect); |
| + return SkScaledImageCache::AddAndLock(key, bitmap); |
| +} |
| + |
| +//// |
| + |
| +SkMaskCache::ID* SkMaskCache::FindAndLock(SkScalar sigma, |
| + unsigned count, |
| + const SkRect rects[], |
| + SkMask* result) { |
| + RectsBlurKey key(sigma, count, rects); |
| + SkBitmap bitmap; |
| + ID* cacheId = SkScaledImageCache::FindAndLock(key, &bitmap); |
| + if (cacheId) { |
| + SkAutoLockPixels autoLockPixels(bitmap); |
| + result->fBounds.set(0, 0, bitmap.width(), bitmap.height()); |
| + result->fRowBytes = result->fBounds.width(); |
| + result->fFormat = SkMask::kA8_Format; |
| + result->fImage = static_cast<uint8_t*>(bitmap.getPixels()); |
| + } |
| + |
| + return cacheId; |
| +} |
| + |
| +SkMaskCache::ID* SkMaskCache::AddAndLock(SkScalar sigma, |
| + unsigned count, |
| + const SkRect rects[], |
| + const SkMask& mask) { |
| + SkBitmap bitmap; |
| + bitmap.installMaskPixels(mask); |
| + RectsBlurKey key(sigma, count, rects); |
| + return SkScaledImageCache::AddAndLock(key, bitmap); |
| +} |
| + |