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

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

Issue 966233002: use colorfilter instead of imagefilter when possible (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 9 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 | no next file » | 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 2008 The Android Open Source Project 2 * Copyright 2008 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 "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkCanvasPriv.h" 9 #include "SkCanvasPriv.h"
10 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
11 #include "SkColorFilter.h"
11 #include "SkDeviceImageFilterProxy.h" 12 #include "SkDeviceImageFilterProxy.h"
12 #include "SkDraw.h" 13 #include "SkDraw.h"
13 #include "SkDrawable.h" 14 #include "SkDrawable.h"
14 #include "SkDrawFilter.h" 15 #include "SkDrawFilter.h"
15 #include "SkDrawLooper.h" 16 #include "SkDrawLooper.h"
16 #include "SkErrorInternals.h" 17 #include "SkErrorInternals.h"
17 #include "SkImage.h" 18 #include "SkImage.h"
18 #include "SkMetaData.h" 19 #include "SkMetaData.h"
19 #include "SkPathOps.h" 20 #include "SkPathOps.h"
20 #include "SkPatchUtils.h" 21 #include "SkPatchUtils.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 SkCanvas* fCanvas; 277 SkCanvas* fCanvas;
277 const DeviceCM* fCurrLayer; 278 const DeviceCM* fCurrLayer;
278 const SkPaint* fPaint; // May be null. 279 const SkPaint* fPaint; // May be null.
279 SkBool8 fSkipEmptyClips; 280 SkBool8 fSkipEmptyClips;
280 281
281 typedef SkDraw INHERITED; 282 typedef SkDraw INHERITED;
282 }; 283 };
283 284
284 ///////////////////////////////////////////////////////////////////////////// 285 /////////////////////////////////////////////////////////////////////////////
285 286
287 static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) {
288 return lazy->isValid() ? lazy->get() : lazy->set(orig);
289 }
290
286 class AutoDrawLooper { 291 class AutoDrawLooper {
287 public: 292 public:
288 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint, 293 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint& paint,
289 bool skipLayerForImageFilter = false, 294 bool skipLayerForImageFilter = false,
290 const SkRect* bounds = NULL) : fOrigPaint(paint) { 295 const SkRect* bounds = NULL) : fOrigPaint(paint) {
291 fCanvas = canvas; 296 fCanvas = canvas;
292 fFilter = canvas->getDrawFilter(); 297 fFilter = canvas->getDrawFilter();
293 fPaint = &fOrigPaint; 298 fPaint = &fOrigPaint;
294 fSaveCount = canvas->getSaveCount(); 299 fSaveCount = canvas->getSaveCount();
295 fDoClearImageFilter = false; 300 fDoClearImageFilter = false;
296 fDone = false; 301 fDone = false;
297 302
298 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { 303 // Transform imagefilter into colorfilter?
304 if (fOrigPaint.getImageFilter()) {
305 SkColorFilter* embeddedCF = NULL;
306 SkColorFilter* paintCF = fOrigPaint.getColorFilter();
307 // When we fix http://code.google.com/p/skia/issues/detail?id=3479 w e can support
308 // composing paintCF w/ embeddedCF.
309 if (NULL == paintCF && fOrigPaint.getImageFilter()->asColorFilter(&e mbeddedCF)) {
Stephen White 2015/03/02 18:50:22 Need to check for !getInput(0) here?
reed2 2015/03/08 21:39:45 asAColorFilter takes care of that check.
310 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
311 paint->setColorFilter(embeddedCF)->unref();
312 paint->setImageFilter(NULL);
313 fPaint = paint;
314 }
315 }
316
317 if (!skipLayerForImageFilter && fPaint->getImageFilter()) {
299 SkPaint tmp; 318 SkPaint tmp;
300 tmp.setImageFilter(fOrigPaint.getImageFilter()); 319 tmp.setImageFilter(fPaint->getImageFilter());
301 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag, 320 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa yer_SaveFlag,
302 true, SkCanvas::kFullLayer_SaveLayer Strategy); 321 true, SkCanvas::kFullLayer_SaveLayer Strategy);
303 // we'll clear the imageFilter for the actual draws in next(), so 322 // we'll clear the imageFilter for the actual draws in next(), so
304 // it will only be applied during the restore(). 323 // it will only be applied during the restore().
305 fDoClearImageFilter = true; 324 fDoClearImageFilter = true;
306 } 325 }
307 326
308 if (SkDrawLooper* looper = paint.getLooper()) { 327 if (SkDrawLooper* looper = paint.getLooper()) {
309 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>( 328 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
310 looper->contextSize()); 329 looper->contextSize());
311 fLooperContext = looper->createContext(canvas, buffer); 330 fLooperContext = looper->createContext(canvas, buffer);
312 fIsSimple = false; 331 fIsSimple = false;
313 } else { 332 } else {
314 fLooperContext = NULL; 333 fLooperContext = NULL;
315 // can we be marked as simple? 334 // can we be marked as simple?
316 fIsSimple = !fFilter && !fDoClearImageFilter; 335 fIsSimple = !fFilter && !fDoClearImageFilter;
317 } 336 }
318 337
319 uint32_t oldFlags = paint.getFlags(); 338 uint32_t oldFlags = paint.getFlags();
320 fNewPaintFlags = filter_paint_flags(props, oldFlags); 339 fNewPaintFlags = filter_paint_flags(props, oldFlags);
321 if (fIsSimple && (fNewPaintFlags != oldFlags)) { 340 if (fIsSimple && (fNewPaintFlags != oldFlags)) {
322 SkPaint* paint = fLazyPaint.set(fOrigPaint); 341 SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
323 paint->setFlags(fNewPaintFlags); 342 paint->setFlags(fNewPaintFlags);
324 fPaint = paint; 343 fPaint = paint;
325 // if we're not simple, doNext() will take care of calling setFlags( ) 344 // if we're not simple, doNext() will take care of calling setFlags( )
326 } 345 }
327 } 346 }
328 347
329 ~AutoDrawLooper() { 348 ~AutoDrawLooper() {
330 if (fDoClearImageFilter) { 349 if (fDoClearImageFilter) {
331 fCanvas->internalRestore(); 350 fCanvas->internalRestore();
332 } 351 }
(...skipping 10 matching lines...) Expand all
343 return false; 362 return false;
344 } else if (fIsSimple) { 363 } else if (fIsSimple) {
345 fDone = true; 364 fDone = true;
346 return !fPaint->nothingToDraw(); 365 return !fPaint->nothingToDraw();
347 } else { 366 } else {
348 return this->doNext(drawType); 367 return this->doNext(drawType);
349 } 368 }
350 } 369 }
351 370
352 private: 371 private:
353 SkLazyPaint fLazyPaint; 372 SkLazyPaint fLazyPaintInit, fLazyPaintPerNext;
354 SkCanvas* fCanvas; 373 SkCanvas* fCanvas;
355 const SkPaint& fOrigPaint; 374 const SkPaint& fOrigPaint;
356 SkDrawFilter* fFilter; 375 SkDrawFilter* fFilter;
357 const SkPaint* fPaint; 376 const SkPaint* fPaint;
358 int fSaveCount; 377 int fSaveCount;
359 uint32_t fNewPaintFlags; 378 uint32_t fNewPaintFlags;
360 bool fDoClearImageFilter; 379 bool fDoClearImageFilter;
361 bool fDone; 380 bool fDone;
362 bool fIsSimple; 381 bool fIsSimple;
363 SkDrawLooper::Context* fLooperContext; 382 SkDrawLooper::Context* fLooperContext;
364 SkSmallAllocator<1, 32> fLooperContextAllocator; 383 SkSmallAllocator<1, 32> fLooperContextAllocator;
365 384
366 bool doNext(SkDrawFilter::Type drawType); 385 bool doNext(SkDrawFilter::Type drawType);
367 }; 386 };
368 387
369 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { 388 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) {
370 fPaint = NULL; 389 fPaint = NULL;
371 SkASSERT(!fIsSimple); 390 SkASSERT(!fIsSimple);
372 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter); 391 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter);
373 392
374 SkPaint* paint = fLazyPaint.set(fOrigPaint); 393 SkPaint* paint = fLazyPaintPerNext.set(fLazyPaintInit.isValid() ? *fLazyPain tInit.get() : fOrigPaint);
375 paint->setFlags(fNewPaintFlags); 394 paint->setFlags(fNewPaintFlags);
376 395
377 if (fDoClearImageFilter) { 396 if (fDoClearImageFilter) {
378 paint->setImageFilter(NULL); 397 paint->setImageFilter(NULL);
379 } 398 }
380 399
381 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { 400 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) {
382 fDone = true; 401 fDone = true;
383 return false; 402 return false;
384 } 403 }
(...skipping 2128 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 } 2532 }
2514 2533
2515 if (matrix) { 2534 if (matrix) {
2516 canvas->concat(*matrix); 2535 canvas->concat(*matrix);
2517 } 2536 }
2518 } 2537 }
2519 2538
2520 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2539 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2521 fCanvas->restoreToCount(fSaveCount); 2540 fCanvas->restoreToCount(fSaveCount);
2522 } 2541 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698