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

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

Issue 617613003: Speculative revert to diagnose crash in chrome. Revert "Add SkCachedData and use it for SkMipMap" (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « src/core/SkBitmapCache.h ('k') | src/core/SkBitmapProcState.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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec); 64 const BitmapRec& rec = static_cast<const BitmapRec&>(baseRec);
65 SkBitmap* result = (SkBitmap*)contextBitmap; 65 SkBitmap* result = (SkBitmap*)contextBitmap;
66 66
67 *result = rec.fBitmap; 67 *result = rec.fBitmap;
68 result->lockPixels(); 68 result->lockPixels();
69 return SkToBool(result->getPixels()); 69 return SkToBool(result->getPixels());
70 } 70 }
71 }; 71 };
72 72
73 #define CHECK_LOCAL(localCache, localName, globalName, ...) \ 73 #define CHECK_LOCAL(localCache, localName, globalName, ...) \
74 ((localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::global Name(__VA_ARGS__)) 74 (localCache) ? localCache->localName(__VA_ARGS__) : SkResourceCache::globalN ame(__VA_ARGS__)
75 75
76 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, SkBitmap* result, 76 bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invSc aleY, SkBitmap* result,
77 SkResourceCache* localCache) { 77 SkResourceCache* localCache) {
78 if (0 == invScaleX || 0 == invScaleY) { 78 if (0 == invScaleX || 0 == invScaleY) {
79 // degenerate, and the key we use for mipmaps 79 // degenerate, and the key we use for mipmaps
80 return false; 80 return false;
81 } 81 }
82 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src)); 82 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src));
83 83
84 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result); 84 return CHECK_LOCAL(localCache, find, Find, key, BitmapRec::Visitor, result);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 CHECK_LOCAL(localCache, add, Add, rec); 119 CHECK_LOCAL(localCache, add, Add, rec);
120 return true; 120 return true;
121 } 121 }
122 } 122 }
123 //////////////////////////////////////////////////////////////////////////////// ////////// 123 //////////////////////////////////////////////////////////////////////////////// //////////
124 124
125 struct MipMapRec : public SkResourceCache::Rec { 125 struct MipMapRec : public SkResourceCache::Rec {
126 MipMapRec(const SkBitmap& src, const SkMipMap* result) 126 MipMapRec(const SkBitmap& src, const SkMipMap* result)
127 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) 127 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src))
128 , fMipMap(result) 128 , fMipMap(SkRef(result))
129 { 129 {}
130 fMipMap->attachToCacheAndRef(); 130
131 virtual ~MipMapRec() {
132 fMipMap->unref();
131 } 133 }
132 134
133 virtual ~MipMapRec() { 135 BitmapKey fKey;
134 fMipMap->detachFromCacheAndUnref(); 136 const SkMipMap* fMipMap;
135 }
136 137
137 virtual const Key& getKey() const SK_OVERRIDE { return fKey; } 138 virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
138 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap ->size(); } 139 virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fMipMap ->getSize(); }
139 140
140 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) { 141 static bool Visitor(const SkResourceCache::Rec& baseRec, void* contextMip) {
141 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec); 142 const MipMapRec& rec = static_cast<const MipMapRec&>(baseRec);
142 const SkMipMap** result = (const SkMipMap**)contextMip; 143 const SkMipMap** result = (const SkMipMap**)contextMip;
143 144
144 *result = SkRef(rec.fMipMap); 145 *result = SkRef(rec.fMipMap);
145 // mipmaps don't use the custom allocator yet, so we don't need to check pixels 146 // mipmaps don't use the custom allocator yet, so we don't need to check pixels
146 return true; 147 return true;
147 } 148 }
148
149 private:
150 BitmapKey fKey;
151 const SkMipMap* fMipMap;
152 }; 149 };
153 150
154 const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src, SkResourceCache* localCache) { 151 const SkMipMap* SkMipMapCache::FindAndRef(const SkBitmap& src) {
155 BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)); 152 BitmapKey key(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src));
156 const SkMipMap* result; 153 const SkMipMap* result;
157 154 if (!SkResourceCache::Find(key, MipMapRec::Visitor, &result)) {
158 if (!CHECK_LOCAL(localCache, find, Find, key, MipMapRec::Visitor, &result)) {
159 result = NULL; 155 result = NULL;
160 } 156 }
161 return result; 157 return result;
162 } 158 }
163 159
164 static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache) { 160 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) {
165 return localCache ? localCache->GetDiscardableFactory() 161 if (result) {
166 : SkResourceCache::GetDiscardableFactory(); 162 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result)));
163 }
167 } 164 }
168 165
169 const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmap& src, SkResourceCache* l ocalCache) {
170 SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache));
171 if (mipmap) {
172 MipMapRec* rec = SkNEW_ARGS(MipMapRec, (src, mipmap));
173 CHECK_LOCAL(localCache, add, Add, rec);
174 }
175 return mipmap;
176 }
177
OLDNEW
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | src/core/SkBitmapProcState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698