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

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

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 6 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 | « include/effects/SkLayerDrawLooper.h ('k') | src/core/SkDrawLooper.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 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkBitmapDevice.h" 11 #include "SkBitmapDevice.h"
12 #include "SkBounder.h" 12 #include "SkBounder.h"
13 #include "SkDeviceImageFilterProxy.h" 13 #include "SkDeviceImageFilterProxy.h"
14 #include "SkDraw.h" 14 #include "SkDraw.h"
15 #include "SkDrawFilter.h" 15 #include "SkDrawFilter.h"
16 #include "SkDrawLooper.h" 16 #include "SkDrawLooper.h"
17 #include "SkMetaData.h" 17 #include "SkMetaData.h"
18 #include "SkPathOps.h" 18 #include "SkPathOps.h"
19 #include "SkPicture.h" 19 #include "SkPicture.h"
20 #include "SkRasterClip.h" 20 #include "SkRasterClip.h"
21 #include "SkRRect.h" 21 #include "SkRRect.h"
22 #include "SkSmallAllocator.h"
22 #include "SkSurface_Base.h" 23 #include "SkSurface_Base.h"
23 #include "SkTemplates.h" 24 #include "SkTemplates.h"
24 #include "SkTextFormatParams.h" 25 #include "SkTextFormatParams.h"
25 #include "SkTLazy.h" 26 #include "SkTLazy.h"
26 #include "SkUtils.h" 27 #include "SkUtils.h"
27 28
28 #if SK_SUPPORT_GPU 29 #if SK_SUPPORT_GPU
29 #include "GrRenderTarget.h" 30 #include "GrRenderTarget.h"
30 #endif 31 #endif
31 32
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 }; 331 };
331 332
332 ///////////////////////////////////////////////////////////////////////////// 333 /////////////////////////////////////////////////////////////////////////////
333 334
334 class AutoDrawLooper { 335 class AutoDrawLooper {
335 public: 336 public:
336 AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, 337 AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint,
337 bool skipLayerForImageFilter = false, 338 bool skipLayerForImageFilter = false,
338 const SkRect* bounds = NULL) : fOrigPaint(paint) { 339 const SkRect* bounds = NULL) : fOrigPaint(paint) {
339 fCanvas = canvas; 340 fCanvas = canvas;
340 fLooper = paint.getLooper();
341 fFilter = canvas->getDrawFilter(); 341 fFilter = canvas->getDrawFilter();
342 fPaint = NULL; 342 fPaint = NULL;
343 fSaveCount = canvas->getSaveCount(); 343 fSaveCount = canvas->getSaveCount();
344 fDoClearImageFilter = false; 344 fDoClearImageFilter = false;
345 fDone = false; 345 fDone = false;
346 346
347 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { 347 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) {
348 SkPaint tmp; 348 SkPaint tmp;
349 tmp.setImageFilter(fOrigPaint.getImageFilter()); 349 tmp.setImageFilter(fOrigPaint.getImageFilter());
350 (void)canvas->internalSaveLayer(bounds, &tmp, 350 (void)canvas->internalSaveLayer(bounds, &tmp,
351 SkCanvas::kARGB_ClipLayer_SaveFlag, true); 351 SkCanvas::kARGB_ClipLayer_SaveFlag, true);
352 // we'll clear the imageFilter for the actual draws in next(), so 352 // we'll clear the imageFilter for the actual draws in next(), so
353 // it will only be applied during the restore(). 353 // it will only be applied during the restore().
354 fDoClearImageFilter = true; 354 fDoClearImageFilter = true;
355 } 355 }
356 356
357 if (fLooper) { 357 if (SkDrawLooper* looper = paint.getLooper()) {
358 fLooper->init(canvas); 358 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex t>(
359 looper->contextSize());
360 fLooperContext = looper->createContext(canvas, buffer);
359 fIsSimple = false; 361 fIsSimple = false;
360 } else { 362 } else {
363 fLooperContext = NULL;
361 // can we be marked as simple? 364 // can we be marked as simple?
362 fIsSimple = !fFilter && !fDoClearImageFilter; 365 fIsSimple = !fFilter && !fDoClearImageFilter;
363 } 366 }
364 } 367 }
365 368
366 ~AutoDrawLooper() { 369 ~AutoDrawLooper() {
367 if (fDoClearImageFilter) { 370 if (fDoClearImageFilter) {
368 fCanvas->internalRestore(); 371 fCanvas->internalRestore();
369 } 372 }
370 SkASSERT(fCanvas->getSaveCount() == fSaveCount); 373 SkASSERT(fCanvas->getSaveCount() == fSaveCount);
(...skipping 13 matching lines...) Expand all
384 return !fPaint->nothingToDraw(); 387 return !fPaint->nothingToDraw();
385 } else { 388 } else {
386 return this->doNext(drawType); 389 return this->doNext(drawType);
387 } 390 }
388 } 391 }
389 392
390 private: 393 private:
391 SkLazyPaint fLazyPaint; 394 SkLazyPaint fLazyPaint;
392 SkCanvas* fCanvas; 395 SkCanvas* fCanvas;
393 const SkPaint& fOrigPaint; 396 const SkPaint& fOrigPaint;
394 SkDrawLooper* fLooper;
395 SkDrawFilter* fFilter; 397 SkDrawFilter* fFilter;
396 const SkPaint* fPaint; 398 const SkPaint* fPaint;
397 int fSaveCount; 399 int fSaveCount;
398 bool fDoClearImageFilter; 400 bool fDoClearImageFilter;
399 bool fDone; 401 bool fDone;
400 bool fIsSimple; 402 bool fIsSimple;
403 SkDrawLooper::Context* fLooperContext;
404 SkSmallAllocator<1, 32> fLooperContextAllocator;
401 405
402 bool doNext(SkDrawFilter::Type drawType); 406 bool doNext(SkDrawFilter::Type drawType);
403 }; 407 };
404 408
405 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { 409 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) {
406 fPaint = NULL; 410 fPaint = NULL;
407 SkASSERT(!fIsSimple); 411 SkASSERT(!fIsSimple);
408 SkASSERT(fLooper || fFilter || fDoClearImageFilter); 412 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter);
409 413
410 SkPaint* paint = fLazyPaint.set(fOrigPaint); 414 SkPaint* paint = fLazyPaint.set(fOrigPaint);
411 415
412 if (fDoClearImageFilter) { 416 if (fDoClearImageFilter) {
413 paint->setImageFilter(NULL); 417 paint->setImageFilter(NULL);
414 } 418 }
415 419
416 if (fLooper && !fLooper->next(fCanvas, paint)) { 420 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) {
417 fDone = true; 421 fDone = true;
418 return false; 422 return false;
419 } 423 }
420 if (fFilter) { 424 if (fFilter) {
421 if (!fFilter->filter(paint, drawType)) { 425 if (!fFilter->filter(paint, drawType)) {
422 fDone = true; 426 fDone = true;
423 return false; 427 return false;
424 } 428 }
425 if (NULL == fLooper) { 429 if (NULL == fLooperContext) {
426 // no looper means we only draw once 430 // no looper means we only draw once
427 fDone = true; 431 fDone = true;
428 } 432 }
429 } 433 }
430 fPaint = paint; 434 fPaint = paint;
431 435
432 // if we only came in here for the imagefilter, mark us as done 436 // if we only came in here for the imagefilter, mark us as done
433 if (!fLooper && !fFilter) { 437 if (!fLooperContext && !fFilter) {
434 fDone = true; 438 fDone = true;
435 } 439 }
436 440
437 // call this after any possible paint modifiers 441 // call this after any possible paint modifiers
438 if (fPaint->nothingToDraw()) { 442 if (fPaint->nothingToDraw()) {
439 fPaint = NULL; 443 fPaint = NULL;
440 return false; 444 return false;
441 } 445 }
442 return true; 446 return true;
443 } 447 }
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 if (!bitmap.allocPixels(info)) { 2455 if (!bitmap.allocPixels(info)) {
2452 return NULL; 2456 return NULL;
2453 } 2457 }
2454 2458
2455 // should this functionality be moved into allocPixels()? 2459 // should this functionality be moved into allocPixels()?
2456 if (!bitmap.info().isOpaque()) { 2460 if (!bitmap.info().isOpaque()) {
2457 bitmap.eraseColor(0); 2461 bitmap.eraseColor(0);
2458 } 2462 }
2459 return SkNEW_ARGS(SkCanvas, (bitmap)); 2463 return SkNEW_ARGS(SkCanvas, (bitmap));
2460 } 2464 }
OLDNEW
« no previous file with comments | « include/effects/SkLayerDrawLooper.h ('k') | src/core/SkDrawLooper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698