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

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

Issue 521433002: harden requirements on SkBitmapCache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 3 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"
11 #include "SkRect.h" 11 #include "SkRect.h"
12 12
13 SkBitmap::Allocator* SkBitmapCache::GetAllocator() {
14 return SkResourceCache::GetAllocator();
15 }
16
13 /** 17 /**
14 This function finds the bounds of the bitmap *within its pixelRef*. 18 This function finds the bounds of the bitmap *within its pixelRef*.
15 If the bitmap lacks a pixelRef, it will return an empty rect, since 19 If the bitmap lacks a pixelRef, it will return an empty rect, since
16 that doesn't make sense. This may be a useful enough function that 20 that doesn't make sense. This may be a useful enough function that
17 it should be somewhere else (in SkBitmap?). 21 it should be somewhere else (in SkBitmap?).
18 */ 22 */
19 static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) { 23 static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
20 if (!(bm.pixelRef())) { 24 if (!(bm.pixelRef())) {
21 return SkIRect::MakeEmpty(); 25 return SkIRect::MakeEmpty();
22 } 26 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src)); 88 BitmapKey key(src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_b itmap(src));
85 return find_and_return(key, result); 89 return find_and_return(key, result);
86 } 90 }
87 91
88 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca leY, 92 void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca leY,
89 const SkBitmap& result) { 93 const SkBitmap& result) {
90 if (0 == invScaleX || 0 == invScaleY) { 94 if (0 == invScaleX || 0 == invScaleY) {
91 // degenerate, and the key we use for mipmaps 95 // degenerate, and the key we use for mipmaps
92 return; 96 return;
93 } 97 }
98 SkASSERT(result.isImmutable());
94 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX , invScaleY, 99 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX , invScaleY,
95 get_bounds_from_bitmap(src), res ult))); 100 get_bounds_from_bitmap(src), res ult)));
96 } 101 }
97 102
98 bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result ) { 103 bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result ) {
99 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height)) ; 104 BitmapKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height)) ;
100 return find_and_return(key, result); 105 return find_and_return(key, result);
101 } 106 }
102 107
103 void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& r esult) { 108 void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& r esult) {
109 SkASSERT(result.isImmutable());
104 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, 110 SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1,
105 SkIRect::MakeWH(width, height), result))); 111 SkIRect::MakeWH(width, height), result)));
106 } 112 }
107 113
108 //////////////////////////////////////////////////////////////////////////////// ////////// 114 //////////////////////////////////////////////////////////////////////////////// //////////
109 115
110 struct MipMapRec : public SkResourceCache::Rec { 116 struct MipMapRec : public SkResourceCache::Rec {
111 MipMapRec(const SkBitmap& src, const SkMipMap* result) 117 MipMapRec(const SkBitmap& src, const SkMipMap* result)
112 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src)) 118 : fKey(src.getGenerationID(), 0, 0, get_bounds_from_bitmap(src))
113 , fMipMap(SkRef(result)) 119 , fMipMap(SkRef(result))
(...skipping 21 matching lines...) Expand all
135 } 141 }
136 return result; 142 return result;
137 } 143 }
138 144
139 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) { 145 void SkMipMapCache::Add(const SkBitmap& src, const SkMipMap* result) {
140 if (result) { 146 if (result) {
141 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result))); 147 SkResourceCache::Add(SkNEW_ARGS(MipMapRec, (src, result)));
142 } 148 }
143 } 149 }
144 150
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