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

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 1414843003: Image filters: Replace all use of tryAllocPixels() with createDevice(). (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix morphology: don't allocate dest or temp until we need them Created 5 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/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.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 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkLightingImageFilter.h" 8 #include "SkLightingImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkDevice.h"
11 #include "SkPoint3.h" 12 #include "SkPoint3.h"
12 #include "SkReadBuffer.h" 13 #include "SkReadBuffer.h"
13 #include "SkTypes.h" 14 #include "SkTypes.h"
14 #include "SkWriteBuffer.h" 15 #include "SkWriteBuffer.h"
15 16
16 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
17 #include "GrContext.h" 18 #include "GrContext.h"
18 #include "GrDrawContext.h" 19 #include "GrDrawContext.h"
19 #include "GrFragmentProcessor.h" 20 #include "GrFragmentProcessor.h"
20 #include "GrInvariantOutput.h" 21 #include "GrInvariantOutput.h"
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 1184
1184 if (bounds.width() < 2 || bounds.height() < 2) { 1185 if (bounds.width() < 2 || bounds.height() < 2) {
1185 return false; 1186 return false;
1186 } 1187 }
1187 1188
1188 SkAutoLockPixels alp(src); 1189 SkAutoLockPixels alp(src);
1189 if (!src.getPixels()) { 1190 if (!src.getPixels()) {
1190 return false; 1191 return false;
1191 } 1192 }
1192 1193
1193 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) { 1194 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
1195 if (!device) {
1194 return false; 1196 return false;
1195 } 1197 }
1198 *dst = device->accessBitmap(false);
1199 SkAutoLockPixels alp_dst(*dst);
1196 1200
1197 SkMatrix matrix(ctx.ctm()); 1201 SkMatrix matrix(ctx.ctm());
1198 matrix.postTranslate(SkIntToScalar(-srcOffset.x()), SkIntToScalar(-srcOffset .y())); 1202 matrix.postTranslate(SkIntToScalar(-srcOffset.x()), SkIntToScalar(-srcOffset .y()));
1199 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(matrix) ); 1203 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(matrix) );
1200 1204
1201 DiffuseLightingType lightingType(fKD); 1205 DiffuseLightingType lightingType(fKD);
1202 offset->fX = bounds.left(); 1206 offset->fX = bounds.left();
1203 offset->fY = bounds.top(); 1207 offset->fY = bounds.top();
1204 bounds.offset(-srcOffset); 1208 bounds.offset(-srcOffset);
1205 switch (transformedLight->type()) { 1209 switch (transformedLight->type()) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 1328
1325 if (bounds.width() < 2 || bounds.height() < 2) { 1329 if (bounds.width() < 2 || bounds.height() < 2) {
1326 return false; 1330 return false;
1327 } 1331 }
1328 1332
1329 SkAutoLockPixels alp(src); 1333 SkAutoLockPixels alp(src);
1330 if (!src.getPixels()) { 1334 if (!src.getPixels()) {
1331 return false; 1335 return false;
1332 } 1336 }
1333 1337
1334 if (!dst->tryAllocPixels(src.info().makeWH(bounds.width(), bounds.height())) ) { 1338 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds.width(), bounds .height()));
1339 if (!device) {
1335 return false; 1340 return false;
1336 } 1341 }
1342 *dst = device->accessBitmap(false);
1343 SkAutoLockPixels alp_dst(*dst);
1337 1344
1338 SpecularLightingType lightingType(fKS, fShininess); 1345 SpecularLightingType lightingType(fKS, fShininess);
1339 offset->fX = bounds.left(); 1346 offset->fX = bounds.left();
1340 offset->fY = bounds.top(); 1347 offset->fY = bounds.top();
1341 SkMatrix matrix(ctx.ctm()); 1348 SkMatrix matrix(ctx.ctm());
1342 matrix.postTranslate(SkIntToScalar(-srcOffset.x()), SkIntToScalar(-srcOffset .y())); 1349 matrix.postTranslate(SkIntToScalar(-srcOffset.x()), SkIntToScalar(-srcOffset .y()));
1343 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(matrix) ); 1350 SkAutoTUnref<SkImageFilterLight> transformedLight(light()->transform(matrix) );
1344 bounds.offset(-srcOffset); 1351 bounds.offset(-srcOffset);
1345 switch (transformedLight->type()) { 1352 switch (transformedLight->type()) {
1346 case SkImageFilterLight::kDistant_LightType: 1353 case SkImageFilterLight::kDistant_LightType:
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
2004 2011
2005 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); 2012 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight);
2006 } 2013 }
2007 2014
2008 #endif 2015 #endif
2009 2016
2010 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 2017 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
2011 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 2018 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
2012 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 2019 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
2013 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 2020 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698