Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: src/core/SkBitmapCache.cpp

Issue 668223002: SkResourceCache::Key namespace support. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unused SkPictureShader headers Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/ImageCacheBench.cpp ('k') | src/core/SkPictureShader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkResourceCache.h" 9 #include "SkResourceCache.h"
10 #include "SkMipMap.h" 10 #include "SkMipMap.h"
(...skipping 10 matching lines...) Expand all
21 it should be somewhere else (in SkBitmap?). 21 it should be somewhere else (in SkBitmap?).
22 */ 22 */
23 static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) { 23 static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
24 if (!(bm.pixelRef())) { 24 if (!(bm.pixelRef())) {
25 return SkIRect::MakeEmpty(); 25 return SkIRect::MakeEmpty();
26 } 26 }
27 SkIPoint origin = bm.pixelRefOrigin(); 27 SkIPoint origin = bm.pixelRefOrigin();
28 return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height()); 28 return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
29 } 29 }
30 30
31 namespace {
32 static unsigned gBitmapKeyNamespaceLabel;
33
31 struct BitmapKey : public SkResourceCache::Key { 34 struct BitmapKey : public SkResourceCache::Key {
32 public: 35 public:
33 BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b ounds) 36 BitmapKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& b ounds)
34 : fGenID(genID) 37 : fGenID(genID)
35 , fScaleX(scaleX) 38 , fScaleX(scaleX)
36 , fScaleY(scaleY) 39 , fScaleY(scaleY)
37 , fBounds(bounds) 40 , fBounds(bounds)
38 { 41 {
39 this->init(sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(f Bounds)); 42 this->init(&gBitmapKeyNamespaceLabel,
43 sizeof(fGenID) + sizeof(fScaleX) + sizeof(fScaleY) + sizeof(f Bounds));
40 } 44 }
41 45
42 uint32_t fGenID; 46 uint32_t fGenID;
43 SkScalar fScaleX; 47 SkScalar fScaleX;
44 SkScalar fScaleY; 48 SkScalar fScaleY;
45 SkIRect fBounds; 49 SkIRect fBounds;
46 }; 50 };
47 51
48 //////////////////////////////////////////////////////////////////////////////// ////////// 52 //////////////////////////////////////////////////////////////////////////////// //////////
49 53
(...skipping 12 matching lines...) Expand all
62 66
63 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap ) { 67 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextBitmap ) {
64 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); 68 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec);
65 SkBitmap* result = (SkBitmap*)contextBitmap; 69 SkBitmap* result = (SkBitmap*)contextBitmap;
66 70
67 *result = rec.fBitmap; 71 *result = rec.fBitmap;
68 result->lockPixels(); 72 result->lockPixels();
69 return SkToBool(result->getPixels()); 73 return SkToBool(result->getPixels());
70 } 74 }
71 }; 75 };
76 } // namespace
72 77
73 #define CHECK_LOCAL(localCache, localName, globalName, ...) \ 78 #define CHECK_LOCAL(localCache, localName, globalName, ...) \
74 ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::global Name(__VA_ARGS__)) 79 ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::global Name(__VA_ARGS__))
75 80
76 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, SkBitmap* result, 81 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, SkBitmap* result,
77 SkResourceCache* localCache) { 82 SkResourceCache* localCache) {
78 if (0 == invScaleX || 0 == invScaleY) { 83 if (0 == invScaleX || 0 == invScaleY) {
79 // degenerate, and the key we use for mipmaps 84 // degenerate, and the key we use for mipmaps
80 return false; 85 return false;
81 } 86 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 178
174 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l ocalCache) { 179 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l ocalCache) {
175 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache)); 180 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache));
176 if (mipmap) { 181 if (mipmap) {
177 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap)); 182 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap));
178 CHECK_LOCAL(localCache, add, Add, rec); 183 CHECK_LOCAL(localCache, add, Add, rec);
179 } 184 }
180 return mipmap; 185 return mipmap;
181 } 186 }
182 187
OLDNEW
« no previous file with comments | « bench/ImageCacheBench.cpp ('k') | src/core/SkPictureShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698