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

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: Add comments. Created 6 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
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"
(...skipping 11 matching lines...) Expand all
22 #include "SkSurface_Base.h" 22 #include "SkSurface_Base.h"
23 #include "SkTemplates.h" 23 #include "SkTemplates.h"
24 #include "SkTextFormatParams.h" 24 #include "SkTextFormatParams.h"
25 #include "SkTLazy.h" 25 #include "SkTLazy.h"
26 #include "SkUtils.h" 26 #include "SkUtils.h"
27 27
28 #if SK_SUPPORT_GPU 28 #if SK_SUPPORT_GPU
29 #include "GrRenderTarget.h" 29 #include "GrRenderTarget.h"
30 #endif 30 #endif
31 31
32 #define kDrawLooperContextStorageLongCount (sizeof(void*) + sizeof(int))
33
32 // experimental for faster tiled drawing... 34 // experimental for faster tiled drawing...
33 //#define SK_ENABLE_CLIP_QUICKREJECT 35 //#define SK_ENABLE_CLIP_QUICKREJECT
34 36
35 //#define SK_TRACE_SAVERESTORE 37 //#define SK_TRACE_SAVERESTORE
36 38
37 #ifdef SK_TRACE_SAVERESTORE 39 #ifdef SK_TRACE_SAVERESTORE
38 static int gLayerCounter; 40 static int gLayerCounter;
39 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL ayerCounter); } 41 static void inc_layer() { ++gLayerCounter; printf("----- inc layer %d\n", gL ayerCounter); }
40 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL ayerCounter); } 42 static void dec_layer() { --gLayerCounter; printf("----- dec layer %d\n", gL ayerCounter); }
41 43
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 SkPaint tmp; 351 SkPaint tmp;
350 tmp.setImageFilter(fOrigPaint.getImageFilter()); 352 tmp.setImageFilter(fOrigPaint.getImageFilter());
351 (void)canvas->internalSaveLayer(bounds, &tmp, 353 (void)canvas->internalSaveLayer(bounds, &tmp,
352 SkCanvas::kARGB_ClipLayer_SaveFlag, true); 354 SkCanvas::kARGB_ClipLayer_SaveFlag, true);
353 // we'll clear the imageFilter for the actual draws in next(), so 355 // we'll clear the imageFilter for the actual draws in next(), so
354 // it will only be applied during the restore(). 356 // it will only be applied during the restore().
355 fDoClearImageFilter = true; 357 fDoClearImageFilter = true;
356 } 358 }
357 359
358 if (fLooper) { 360 if (fLooper) {
359 fLooper->init(canvas); 361 fLooperContext = fLooper->init(canvas, fLooperContextStorage,
362 sizeof(fLooperContextStorage));
360 fIsSimple = false; 363 fIsSimple = false;
361 } else { 364 } else {
362 // can we be marked as simple? 365 // can we be marked as simple?
363 fIsSimple = !fFilter && !fDoClearImageFilter; 366 fIsSimple = !fFilter && !fDoClearImageFilter;
364 } 367 }
365 } 368 }
366 369
367 ~AutoDrawLooper() { 370 ~AutoDrawLooper() {
368 if (fDoClearImageFilter) { 371 if (fDoClearImageFilter) {
369 fCanvas->internalRestore(); 372 fCanvas->internalRestore();
370 } 373 }
371 SkASSERT(fCanvas->getSaveCount() == fSaveCount); 374 SkASSERT(fCanvas->getSaveCount() == fSaveCount);
375 if (fLooper) {
376 SkASSERT(fLooperContext);
377 fLooperContext->cleanup(fLooperContextStorage);
378 }
372 } 379 }
373 380
374 const SkPaint& paint() const { 381 const SkPaint& paint() const {
375 SkASSERT(fPaint); 382 SkASSERT(fPaint);
376 return *fPaint; 383 return *fPaint;
377 } 384 }
378 385
379 bool next(SkDrawFilter::Type drawType) { 386 bool next(SkDrawFilter::Type drawType) {
380 if (fDone) { 387 if (fDone) {
381 return false; 388 return false;
(...skipping 10 matching lines...) Expand all
392 SkLazyPaint fLazyPaint; 399 SkLazyPaint fLazyPaint;
393 SkCanvas* fCanvas; 400 SkCanvas* fCanvas;
394 const SkPaint& fOrigPaint; 401 const SkPaint& fOrigPaint;
395 SkDrawLooper* fLooper; 402 SkDrawLooper* fLooper;
396 SkDrawFilter* fFilter; 403 SkDrawFilter* fFilter;
397 const SkPaint* fPaint; 404 const SkPaint* fPaint;
398 int fSaveCount; 405 int fSaveCount;
399 bool fDoClearImageFilter; 406 bool fDoClearImageFilter;
400 bool fDone; 407 bool fDone;
401 bool fIsSimple; 408 bool fIsSimple;
409 SkDrawLooper::DrawContext* fLooperContext;
410 uint32_t fLooperContextStorage[kDrawLooperContextStorageLongCount];
402 411
403 bool doNext(SkDrawFilter::Type drawType); 412 bool doNext(SkDrawFilter::Type drawType);
404 }; 413 };
405 414
406 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { 415 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) {
407 fPaint = NULL; 416 fPaint = NULL;
408 SkASSERT(!fIsSimple); 417 SkASSERT(!fIsSimple);
409 SkASSERT(fLooper || fFilter || fDoClearImageFilter); 418 SkASSERT(fLooper || fFilter || fDoClearImageFilter);
419 SkASSERT(!fLooper || fLooperContext);
410 420
411 SkPaint* paint = fLazyPaint.set(fOrigPaint); 421 SkPaint* paint = fLazyPaint.set(fOrigPaint);
412 422
413 if (fDoClearImageFilter) { 423 if (fDoClearImageFilter) {
414 paint->setImageFilter(NULL); 424 paint->setImageFilter(NULL);
415 } 425 }
416 426
417 if (fLooper && !fLooper->next(fCanvas, paint)) { 427 if (fLooper && !fLooperContext->next(fCanvas, paint)) {
418 fDone = true; 428 fDone = true;
419 return false; 429 return false;
420 } 430 }
421 if (fFilter) { 431 if (fFilter) {
422 if (!fFilter->filter(paint, drawType)) { 432 if (!fFilter->filter(paint, drawType)) {
423 fDone = true; 433 fDone = true;
424 return false; 434 return false;
425 } 435 }
426 if (NULL == fLooper) { 436 if (NULL == fLooper) {
427 // no looper means we only draw once 437 // no looper means we only draw once
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 return *paint; 2228 return *paint;
2219 } 2229 }
2220 2230
2221 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); } 2231 const SkRegion& SkCanvas::LayerIter::clip() const { return fImpl->getClip(); }
2222 int SkCanvas::LayerIter::x() const { return fImpl->getX(); } 2232 int SkCanvas::LayerIter::x() const { return fImpl->getX(); }
2223 int SkCanvas::LayerIter::y() const { return fImpl->getY(); } 2233 int SkCanvas::LayerIter::y() const { return fImpl->getY(); }
2224 2234
2225 /////////////////////////////////////////////////////////////////////////////// 2235 ///////////////////////////////////////////////////////////////////////////////
2226 2236
2227 SkCanvas::ClipVisitor::~ClipVisitor() { } 2237 SkCanvas::ClipVisitor::~ClipVisitor() { }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698