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

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

Issue 1617183004: Anisotropic mipmap fixes (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: SkIntToScalar Created 4 years, 11 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 | « no previous file | src/core/SkMipMap.h » ('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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 154
155 // Our default return state is to downgrade the request to Low, w/ or w/o se tting fBitmap 155 // Our default return state is to downgrade the request to Low, w/ or w/o se tting fBitmap
156 // to a valid bitmap. 156 // to a valid bitmap.
157 fQuality = kLow_SkFilterQuality; 157 fQuality = kLow_SkFilterQuality;
158 158
159 SkSize invScaleSize; 159 SkSize invScaleSize;
160 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) { 160 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
161 return false; 161 return false;
162 } 162 }
163
164 #ifdef SK_SUPPORT_LEGACY_ANISOTROPIC_MIPMAPS
163 SkScalar invScale = SkScalarSqrt(invScaleSize.width() * invScaleSize.height( )); 165 SkScalar invScale = SkScalarSqrt(invScaleSize.width() * invScaleSize.height( ));
164 166 #else
167 // Use the largest (non-inverse) scale, to ensure anisotropic consistency.
168 SkASSERT(invScaleSize.width() >= 0 && invScaleSize.height() >= 0);
169 const SkScalar invScale = SkTMin(invScaleSize.width(), invScaleSize.height() );
170 #endif
171
165 if (invScale > SK_Scalar1) { 172 if (invScale > SK_Scalar1) {
166 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc())); 173 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc()));
167 if (nullptr == fCurrMip.get()) { 174 if (nullptr == fCurrMip.get()) {
168 SkBitmap orig; 175 SkBitmap orig;
169 if (!provider.asBitmap(&orig)) { 176 if (!provider.asBitmap(&orig)) {
170 return false; 177 return false;
171 } 178 }
172 fCurrMip.reset(SkMipMapCache::AddAndRef(orig)); 179 fCurrMip.reset(SkMipMapCache::AddAndRef(orig));
173 if (nullptr == fCurrMip.get()) { 180 if (nullptr == fCurrMip.get()) {
174 return false; 181 return false;
175 } 182 }
176 } 183 }
177 // diagnostic for a crasher... 184 // diagnostic for a crasher...
178 if (nullptr == fCurrMip->data()) { 185 if (nullptr == fCurrMip->data()) {
179 sk_throw(); 186 sk_throw();
180 } 187 }
181 188
182 SkScalar levelScale = SkScalarInvert(invScale); 189 SkScalar levelScale = SkScalarInvert(invScale);
183 SkMipMap::Level level; 190 SkMipMap::Level level;
184 if (fCurrMip->extractLevel(levelScale, &level)) { 191 if (fCurrMip->extractLevel(levelScale, &level)) {
185 SkScalar invScaleFixup = level.fScale; 192 const SkSize& invScaleFixup = level.fScale;
186 fInvMatrix.postScale(invScaleFixup, invScaleFixup); 193 fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
187 194
188 // todo: if we could wrap the fCurrMip in a pixelref, then we could just install 195 // todo: if we could wrap the fCurrMip in a pixelref, then we could just install
189 // that here, and not need to explicitly track it ourselves. 196 // that here, and not need to explicitly track it ourselves.
190 return fResultBitmap.installPixels(level.fPixmap); 197 return fResultBitmap.installPixels(level.fPixmap);
191 } else { 198 } else {
192 // failed to extract, so release the mipmap 199 // failed to extract, so release the mipmap
193 fCurrMip.reset(nullptr); 200 fCurrMip.reset(nullptr);
194 } 201 }
195 } 202 }
196 return false; 203 return false;
197 } 204 }
(...skipping 19 matching lines...) Expand all
217 fResultBitmap.getColorTable()); 224 fResultBitmap.getColorTable());
218 } 225 }
219 226
220 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, 227 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm,
221 const SkMa trix& inverse, 228 const SkMa trix& inverse,
222 SkFilterQu ality quality, 229 SkFilterQu ality quality,
223 void* stor age, size_t size) { 230 void* stor age, size_t size) {
224 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); 231 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality);
225 } 232 }
226 233
OLDNEW
« no previous file with comments | « no previous file | src/core/SkMipMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698