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

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

Issue 2029373004: respect srgb gamma when building mips (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix warning Created 4 years, 6 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/SkBitmapController.h ('k') | src/core/SkBitmapProcShader.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 2015 Google Inc. 2 * Copyright 2015 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapController.h" 9 #include "SkBitmapController.h"
10 #include "SkBitmapProvider.h" 10 #include "SkBitmapProvider.h"
(...skipping 26 matching lines...) Expand all
37 37
38 //////////////////////////////////////////////////////////////////////////////// /////////////////// 38 //////////////////////////////////////////////////////////////////////////////// ///////////////////
39 39
40 #include "SkBitmapCache.h" 40 #include "SkBitmapCache.h"
41 #include "SkBitmapScaler.h" 41 #include "SkBitmapScaler.h"
42 #include "SkMipMap.h" 42 #include "SkMipMap.h"
43 #include "SkResourceCache.h" 43 #include "SkResourceCache.h"
44 44
45 class SkDefaultBitmapControllerState : public SkBitmapController::State { 45 class SkDefaultBitmapControllerState : public SkBitmapController::State {
46 public: 46 public:
47 SkDefaultBitmapControllerState(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality); 47 SkDefaultBitmapControllerState(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality,
48 SkSourceGammaTreatment);
48 49
49 private: 50 private:
50 SkBitmap fResultBitmap; 51 SkBitmap fResultBitmap;
52 SkSourceGammaTreatment fSrcGammaTreatment;
51 SkAutoTUnref<const SkMipMap> fCurrMip; 53 SkAutoTUnref<const SkMipMap> fCurrMip;
52 54
53 bool processHQRequest(const SkBitmapProvider&); 55 bool processHQRequest(const SkBitmapProvider&);
54 bool processMediumRequest(const SkBitmapProvider&); 56 bool processMediumRequest(const SkBitmapProvider&);
55 }; 57 };
56 58
57 // Check to see that the size of the bitmap that would be produced by 59 // Check to see that the size of the bitmap that would be produced by
58 // scaling by the given inverted matrix is less than the maximum allowed. 60 // scaling by the given inverted matrix is less than the maximum allowed.
59 static inline bool cache_size_okay(const SkBitmapProvider& provider, const SkMat rix& invMat) { 61 static inline bool cache_size_okay(const SkBitmapProvider& provider, const SkMat rix& invMat) {
60 size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByte Limit(); 62 size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByte Limit();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // Our default return state is to downgrade the request to Low, w/ or w/o se tting fBitmap 159 // Our default return state is to downgrade the request to Low, w/ or w/o se tting fBitmap
158 // to a valid bitmap. 160 // to a valid bitmap.
159 fQuality = kLow_SkFilterQuality; 161 fQuality = kLow_SkFilterQuality;
160 162
161 SkSize invScaleSize; 163 SkSize invScaleSize;
162 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) { 164 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
163 return false; 165 return false;
164 } 166 }
165 167
166 if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) { 168 if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) {
167 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc())); 169 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc(), fSrcG ammaTreatment));
168 if (nullptr == fCurrMip.get()) { 170 if (nullptr == fCurrMip.get()) {
169 SkBitmap orig; 171 SkBitmap orig;
170 if (!provider.asBitmap(&orig)) { 172 if (!provider.asBitmap(&orig)) {
171 return false; 173 return false;
172 } 174 }
173 fCurrMip.reset(SkMipMapCache::AddAndRef(orig)); 175 fCurrMip.reset(SkMipMapCache::AddAndRef(orig, fSrcGammaTreatment));
174 if (nullptr == fCurrMip.get()) { 176 if (nullptr == fCurrMip.get()) {
175 return false; 177 return false;
176 } 178 }
177 } 179 }
178 // diagnostic for a crasher... 180 // diagnostic for a crasher...
179 if (nullptr == fCurrMip->data()) { 181 if (nullptr == fCurrMip->data()) {
180 sk_throw(); 182 sk_throw();
181 } 183 }
182 184
183 const SkSize scale = SkSize::Make(SkScalarInvert(invScaleSize.width()), 185 const SkSize scale = SkSize::Make(SkScalarInvert(invScaleSize.width()),
184 SkScalarInvert(invScaleSize.height())) ; 186 SkScalarInvert(invScaleSize.height())) ;
185 SkMipMap::Level level; 187 SkMipMap::Level level;
186 if (fCurrMip->extractLevel(scale, &level)) { 188 if (fCurrMip->extractLevel(scale, &level)) {
187 const SkSize& invScaleFixup = level.fScale; 189 const SkSize& invScaleFixup = level.fScale;
188 fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height()); 190 fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
189 191
190 // todo: if we could wrap the fCurrMip in a pixelref, then we could just install 192 // todo: if we could wrap the fCurrMip in a pixelref, then we could just install
191 // that here, and not need to explicitly track it ourselves. 193 // that here, and not need to explicitly track it ourselves.
192 return fResultBitmap.installPixels(level.fPixmap); 194 return fResultBitmap.installPixels(level.fPixmap);
193 } else { 195 } else {
194 // failed to extract, so release the mipmap 196 // failed to extract, so release the mipmap
195 fCurrMip.reset(nullptr); 197 fCurrMip.reset(nullptr);
196 } 198 }
197 } 199 }
198 return false; 200 return false;
199 } 201 }
200 202
201 SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapPro vider& provider, 203 SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapPro vider& provider,
202 const SkMatrix& i nv, 204 const SkMatrix& i nv,
203 SkFilterQuality q ual) { 205 SkFilterQuality q ual,
206 SkSourceGammaTrea tment treatment) {
204 fInvMatrix = inv; 207 fInvMatrix = inv;
205 fQuality = qual; 208 fQuality = qual;
209 fSrcGammaTreatment = treatment;
206 210
207 if (this->processHQRequest(provider) || this->processMediumRequest(provider) ) { 211 if (this->processHQRequest(provider) || this->processMediumRequest(provider) ) {
208 SkASSERT(fResultBitmap.getPixels()); 212 SkASSERT(fResultBitmap.getPixels());
209 } else { 213 } else {
210 (void)provider.asBitmap(&fResultBitmap); 214 (void)provider.asBitmap(&fResultBitmap);
211 fResultBitmap.lockPixels(); 215 fResultBitmap.lockPixels();
212 // lock may fail to give us pixels 216 // lock may fail to give us pixels
213 } 217 }
214 SkASSERT(fQuality <= kLow_SkFilterQuality); 218 SkASSERT(fQuality <= kLow_SkFilterQuality);
215 219
216 // fResultBitmap.getPixels() may be null, but our caller knows to check fPix map.addr() 220 // fResultBitmap.getPixels() may be null, but our caller knows to check fPix map.addr()
217 // and will destroy us if it is nullptr. 221 // and will destroy us if it is nullptr.
218 fPixmap.reset(fResultBitmap.info(), fResultBitmap.getPixels(), fResultBitmap .rowBytes(), 222 fPixmap.reset(fResultBitmap.info(), fResultBitmap.getPixels(), fResultBitmap .rowBytes(),
219 fResultBitmap.getColorTable()); 223 fResultBitmap.getColorTable());
220 } 224 }
221 225
222 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, 226 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm,
223 const SkMa trix& inverse, 227 const SkMa trix& inverse,
224 SkFilterQu ality quality, 228 SkFilterQu ality quality,
225 void* stor age, size_t size) { 229 void* stor age, size_t size) {
226 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); 230 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality,
231 fSrcGammaTreatment) ;
227 } 232 }
OLDNEW
« no previous file with comments | « src/core/SkBitmapController.h ('k') | src/core/SkBitmapProcShader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698