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

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

Issue 1686563002: Relocate anisotropic mipmap logic to SkMipMap::extractLevel() (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 | « gm/showmiplevels.cpp ('k') | 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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 // 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
160 // to a valid bitmap. 160 // to a valid bitmap.
161 fQuality = kLow_SkFilterQuality; 161 fQuality = kLow_SkFilterQuality;
162 162
163 SkSize invScaleSize; 163 SkSize invScaleSize;
164 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) { 164 if (!fInvMatrix.decomposeScale(&invScaleSize, nullptr)) {
165 return false; 165 return false;
166 } 166 }
167 167
168 // Use the smallest (non-inverse) scale to match the GPU impl. 168 if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) {
169 SkASSERT(invScaleSize.width() >= 0 && invScaleSize.height() >= 0);
170 const SkScalar invScale = SkTMax(invScaleSize.width(), invScaleSize.height() );
171
172 if (invScale > SK_Scalar1) {
173 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc())); 169 fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc()));
174 if (nullptr == fCurrMip.get()) { 170 if (nullptr == fCurrMip.get()) {
175 SkBitmap orig; 171 SkBitmap orig;
176 if (!provider.asBitmap(&orig)) { 172 if (!provider.asBitmap(&orig)) {
177 return false; 173 return false;
178 } 174 }
179 fCurrMip.reset(SkMipMapCache::AddAndRef(orig)); 175 fCurrMip.reset(SkMipMapCache::AddAndRef(orig));
180 if (nullptr == fCurrMip.get()) { 176 if (nullptr == fCurrMip.get()) {
181 return false; 177 return false;
182 } 178 }
183 } 179 }
184 // diagnostic for a crasher... 180 // diagnostic for a crasher...
185 if (nullptr == fCurrMip->data()) { 181 if (nullptr == fCurrMip->data()) {
186 sk_throw(); 182 sk_throw();
187 } 183 }
188 184
189 SkScalar levelScale = SkScalarInvert(invScale); 185 const SkSize scale = SkSize::Make(SkScalarInvert(invScaleSize.width()),
186 SkScalarInvert(invScaleSize.height())) ;
190 SkMipMap::Level level; 187 SkMipMap::Level level;
191 if (fCurrMip->extractLevel(levelScale, &level)) { 188 if (fCurrMip->extractLevel(scale, &level)) {
192 const SkSize& invScaleFixup = level.fScale; 189 const SkSize& invScaleFixup = level.fScale;
193 fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height()); 190 fInvMatrix.postScale(invScaleFixup.width(), invScaleFixup.height());
194 191
195 // 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
196 // that here, and not need to explicitly track it ourselves. 193 // that here, and not need to explicitly track it ourselves.
197 return fResultBitmap.installPixels(level.fPixmap); 194 return fResultBitmap.installPixels(level.fPixmap);
198 } else { 195 } else {
199 // failed to extract, so release the mipmap 196 // failed to extract, so release the mipmap
200 fCurrMip.reset(nullptr); 197 fCurrMip.reset(nullptr);
201 } 198 }
(...skipping 22 matching lines...) Expand all
224 fResultBitmap.getColorTable()); 221 fResultBitmap.getColorTable());
225 } 222 }
226 223
227 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm, 224 SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi tmapProvider& bm,
228 const SkMa trix& inverse, 225 const SkMa trix& inverse,
229 SkFilterQu ality quality, 226 SkFilterQu ality quality,
230 void* stor age, size_t size) { 227 void* stor age, size_t size) {
231 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality); 228 return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality);
232 } 229 }
233 230
OLDNEW
« no previous file with comments | « gm/showmiplevels.cpp ('k') | src/core/SkMipMap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698