OLD | NEW |
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 |
8 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
9 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
10 #include "SkBitmapDevice.h" | 11 #include "SkBitmapDevice.h" |
11 #include "SkDeviceImageFilterProxy.h" | 12 #include "SkDeviceImageFilterProxy.h" |
12 #include "SkDraw.h" | 13 #include "SkDraw.h" |
13 #include "SkDrawFilter.h" | 14 #include "SkDrawFilter.h" |
14 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
15 #include "SkMetaData.h" | 16 #include "SkMetaData.h" |
16 #include "SkPathOps.h" | 17 #include "SkPathOps.h" |
17 #include "SkPatchUtils.h" | 18 #include "SkPatchUtils.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 typedef SkTLazy<SkPaint> SkLazyPaint; | 60 typedef SkTLazy<SkPaint> SkLazyPaint; |
60 | 61 |
61 void SkCanvas::predrawNotify() { | 62 void SkCanvas::predrawNotify() { |
62 if (fSurfaceBase) { | 63 if (fSurfaceBase) { |
63 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); | 64 fSurfaceBase->aboutToDraw(SkSurface::kRetain_ContentChangeMode); |
64 } | 65 } |
65 } | 66 } |
66 | 67 |
67 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
68 | 69 |
69 static uint32_t filter_paint_flags(const SkSurfaceProps& props, uint32_t flags)
{ | |
70 const uint32_t propFlags = props.flags(); | |
71 if (propFlags & SkSurfaceProps::kDisallowDither_Flag) { | |
72 flags &= ~SkPaint::kDither_Flag; | |
73 } | |
74 if (propFlags & SkSurfaceProps::kDisallowAntiAlias_Flag) { | |
75 flags &= ~SkPaint::kAntiAlias_Flag; | |
76 } | |
77 return flags; | |
78 } | |
79 | |
80 /////////////////////////////////////////////////////////////////////////////// | |
81 | |
82 /* This is the record we keep for each SkBaseDevice that the user installs. | 70 /* This is the record we keep for each SkBaseDevice that the user installs. |
83 The clip/matrix/proc are fields that reflect the top of the save/restore | 71 The clip/matrix/proc are fields that reflect the top of the save/restore |
84 stack. Whenever the canvas changes, it marks a dirty flag, and then before | 72 stack. Whenever the canvas changes, it marks a dirty flag, and then before |
85 these are used (assuming we're not on a layer) we rebuild these cache | 73 these are used (assuming we're not on a layer) we rebuild these cache |
86 values: they reflect the top of the save stack, but translated and clipped | 74 values: they reflect the top of the save stack, but translated and clipped |
87 by the device's XY offset and bitmap-bounds. | 75 by the device's XY offset and bitmap-bounds. |
88 */ | 76 */ |
89 struct DeviceCM { | 77 struct DeviceCM { |
90 DeviceCM* fNext; | 78 DeviceCM* fNext; |
91 SkBaseDevice* fDevice; | 79 SkBaseDevice* fDevice; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 const SkPaint* fPaint; // May be null. | 243 const SkPaint* fPaint; // May be null. |
256 SkBool8 fSkipEmptyClips; | 244 SkBool8 fSkipEmptyClips; |
257 | 245 |
258 typedef SkDraw INHERITED; | 246 typedef SkDraw INHERITED; |
259 }; | 247 }; |
260 | 248 |
261 ///////////////////////////////////////////////////////////////////////////// | 249 ///////////////////////////////////////////////////////////////////////////// |
262 | 250 |
263 class AutoDrawLooper { | 251 class AutoDrawLooper { |
264 public: | 252 public: |
265 AutoDrawLooper(SkCanvas* canvas, const SkSurfaceProps& props, const SkPaint&
paint, | 253 AutoDrawLooper(SkCanvas* canvas, const SkPaint& paint, |
266 bool skipLayerForImageFilter = false, | 254 bool skipLayerForImageFilter = false, |
267 const SkRect* bounds = NULL) : fOrigPaint(paint) { | 255 const SkRect* bounds = NULL) : fOrigPaint(paint) { |
268 fCanvas = canvas; | 256 fCanvas = canvas; |
269 fFilter = canvas->getDrawFilter(); | 257 fFilter = canvas->getDrawFilter(); |
270 fPaint = &fOrigPaint; | 258 fPaint = NULL; |
271 fSaveCount = canvas->getSaveCount(); | 259 fSaveCount = canvas->getSaveCount(); |
272 fDoClearImageFilter = false; | 260 fDoClearImageFilter = false; |
273 fDone = false; | 261 fDone = false; |
274 | 262 |
275 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { | 263 if (!skipLayerForImageFilter && fOrigPaint.getImageFilter()) { |
276 SkPaint tmp; | 264 SkPaint tmp; |
277 tmp.setImageFilter(fOrigPaint.getImageFilter()); | 265 tmp.setImageFilter(fOrigPaint.getImageFilter()); |
278 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa
yer_SaveFlag, | 266 (void)canvas->internalSaveLayer(bounds, &tmp, SkCanvas::kARGB_ClipLa
yer_SaveFlag, |
279 true, SkCanvas::kFullLayer_SaveLayer
Strategy); | 267 true, SkCanvas::kFullLayer_SaveLayer
Strategy); |
280 // we'll clear the imageFilter for the actual draws in next(), so | 268 // we'll clear the imageFilter for the actual draws in next(), so |
281 // it will only be applied during the restore(). | 269 // it will only be applied during the restore(). |
282 fDoClearImageFilter = true; | 270 fDoClearImageFilter = true; |
283 } | 271 } |
284 | 272 |
285 if (SkDrawLooper* looper = paint.getLooper()) { | 273 if (SkDrawLooper* looper = paint.getLooper()) { |
286 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( | 274 void* buffer = fLooperContextAllocator.reserveT<SkDrawLooper::Contex
t>( |
287 looper->contextSize()); | 275 looper->contextSize()); |
288 fLooperContext = looper->createContext(canvas, buffer); | 276 fLooperContext = looper->createContext(canvas, buffer); |
289 fIsSimple = false; | 277 fIsSimple = false; |
290 } else { | 278 } else { |
291 fLooperContext = NULL; | 279 fLooperContext = NULL; |
292 // can we be marked as simple? | 280 // can we be marked as simple? |
293 fIsSimple = !fFilter && !fDoClearImageFilter; | 281 fIsSimple = !fFilter && !fDoClearImageFilter; |
294 } | 282 } |
295 | |
296 uint32_t oldFlags = paint.getFlags(); | |
297 fNewPaintFlags = filter_paint_flags(props, oldFlags); | |
298 if (fIsSimple && (fNewPaintFlags != oldFlags)) { | |
299 SkPaint* paint = fLazyPaint.set(fOrigPaint); | |
300 paint->setFlags(fNewPaintFlags); | |
301 fPaint = paint; | |
302 // if we're not simple, doNext() will take care of calling setFlags(
) | |
303 } | |
304 } | 283 } |
305 | 284 |
306 ~AutoDrawLooper() { | 285 ~AutoDrawLooper() { |
307 if (fDoClearImageFilter) { | 286 if (fDoClearImageFilter) { |
308 fCanvas->internalRestore(); | 287 fCanvas->internalRestore(); |
309 } | 288 } |
310 SkASSERT(fCanvas->getSaveCount() == fSaveCount); | 289 SkASSERT(fCanvas->getSaveCount() == fSaveCount); |
311 } | 290 } |
312 | 291 |
313 const SkPaint& paint() const { | 292 const SkPaint& paint() const { |
314 SkASSERT(fPaint); | 293 SkASSERT(fPaint); |
315 return *fPaint; | 294 return *fPaint; |
316 } | 295 } |
317 | 296 |
318 bool next(SkDrawFilter::Type drawType) { | 297 bool next(SkDrawFilter::Type drawType) { |
319 if (fDone) { | 298 if (fDone) { |
320 return false; | 299 return false; |
321 } else if (fIsSimple) { | 300 } else if (fIsSimple) { |
322 fDone = true; | 301 fDone = true; |
| 302 fPaint = &fOrigPaint; |
323 return !fPaint->nothingToDraw(); | 303 return !fPaint->nothingToDraw(); |
324 } else { | 304 } else { |
325 return this->doNext(drawType); | 305 return this->doNext(drawType); |
326 } | 306 } |
327 } | 307 } |
328 | 308 |
329 private: | 309 private: |
330 SkLazyPaint fLazyPaint; | 310 SkLazyPaint fLazyPaint; |
331 SkCanvas* fCanvas; | 311 SkCanvas* fCanvas; |
332 const SkPaint& fOrigPaint; | 312 const SkPaint& fOrigPaint; |
333 SkDrawFilter* fFilter; | 313 SkDrawFilter* fFilter; |
334 const SkPaint* fPaint; | 314 const SkPaint* fPaint; |
335 int fSaveCount; | 315 int fSaveCount; |
336 uint32_t fNewPaintFlags; | |
337 bool fDoClearImageFilter; | 316 bool fDoClearImageFilter; |
338 bool fDone; | 317 bool fDone; |
339 bool fIsSimple; | 318 bool fIsSimple; |
340 SkDrawLooper::Context* fLooperContext; | 319 SkDrawLooper::Context* fLooperContext; |
341 SkSmallAllocator<1, 32> fLooperContextAllocator; | 320 SkSmallAllocator<1, 32> fLooperContextAllocator; |
342 | 321 |
343 bool doNext(SkDrawFilter::Type drawType); | 322 bool doNext(SkDrawFilter::Type drawType); |
344 }; | 323 }; |
345 | 324 |
346 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { | 325 bool AutoDrawLooper::doNext(SkDrawFilter::Type drawType) { |
347 fPaint = NULL; | 326 fPaint = NULL; |
348 SkASSERT(!fIsSimple); | 327 SkASSERT(!fIsSimple); |
349 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter); | 328 SkASSERT(fLooperContext || fFilter || fDoClearImageFilter); |
350 | 329 |
351 SkPaint* paint = fLazyPaint.set(fOrigPaint); | 330 SkPaint* paint = fLazyPaint.set(fOrigPaint); |
352 paint->setFlags(fNewPaintFlags); | |
353 | 331 |
354 if (fDoClearImageFilter) { | 332 if (fDoClearImageFilter) { |
355 paint->setImageFilter(NULL); | 333 paint->setImageFilter(NULL); |
356 } | 334 } |
357 | 335 |
358 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { | 336 if (fLooperContext && !fLooperContext->next(fCanvas, paint)) { |
359 fDone = true; | 337 fDone = true; |
360 return false; | 338 return false; |
361 } | 339 } |
362 if (fFilter) { | 340 if (fFilter) { |
(...skipping 14 matching lines...) Expand all Loading... |
377 } | 355 } |
378 | 356 |
379 // call this after any possible paint modifiers | 357 // call this after any possible paint modifiers |
380 if (fPaint->nothingToDraw()) { | 358 if (fPaint->nothingToDraw()) { |
381 fPaint = NULL; | 359 fPaint = NULL; |
382 return false; | 360 return false; |
383 } | 361 } |
384 return true; | 362 return true; |
385 } | 363 } |
386 | 364 |
| 365 #include "SkColorPriv.h" |
| 366 |
387 ////////// macros to place around the internal draw calls ////////////////// | 367 ////////// macros to place around the internal draw calls ////////////////// |
388 | 368 |
389 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ | 369 #define LOOPER_BEGIN_DRAWDEVICE(paint, type) \ |
390 this->predrawNotify(); \ | 370 this->predrawNotify(); \ |
391 AutoDrawLooper looper(this, fProps, paint, true); \ | 371 AutoDrawLooper looper(this, paint, true); \ |
392 while (looper.next(type)) { \ | 372 while (looper.next(type)) { \ |
393 SkDrawIter iter(this); | 373 SkDrawIter iter(this); |
394 | 374 |
395 #define LOOPER_BEGIN(paint, type, bounds) \ | 375 #define LOOPER_BEGIN(paint, type, bounds) \ |
396 this->predrawNotify(); \ | 376 this->predrawNotify(); \ |
397 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ | 377 AutoDrawLooper looper(this, paint, false, bounds); \ |
398 while (looper.next(type)) { \ | 378 while (looper.next(type)) { \ |
399 SkDrawIter iter(this); | 379 SkDrawIter iter(this); |
400 | 380 |
401 #define LOOPER_END } | 381 #define LOOPER_END } |
402 | 382 |
403 //////////////////////////////////////////////////////////////////////////// | 383 //////////////////////////////////////////////////////////////////////////// |
404 | 384 |
405 void SkCanvas::setupDevice(SkBaseDevice* device) { | |
406 device->setPixelGeometry(fProps.pixelGeometry()); | |
407 } | |
408 | |
409 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { | 385 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
410 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; | 386 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; |
411 fCachedLocalClipBounds.setEmpty(); | 387 fCachedLocalClipBounds.setEmpty(); |
412 fCachedLocalClipBoundsDirty = true; | 388 fCachedLocalClipBoundsDirty = true; |
413 fAllowSoftClip = true; | 389 fAllowSoftClip = true; |
414 fAllowSimplifyClip = false; | 390 fAllowSimplifyClip = false; |
415 fDeviceCMDirty = true; | 391 fDeviceCMDirty = true; |
416 fSaveLayerCount = 0; | 392 fSaveLayerCount = 0; |
417 fCullCount = 0; | 393 fCullCount = 0; |
418 fMetaData = NULL; | 394 fMetaData = NULL; |
419 | 395 |
| 396 if (device && device->forceConservativeRasterClip()) { |
| 397 fConservativeRasterClip = true; |
| 398 } |
| 399 |
420 fMCRec = (MCRec*)fMCStack.push_back(); | 400 fMCRec = (MCRec*)fMCStack.push_back(); |
421 new (fMCRec) MCRec(fConservativeRasterClip); | 401 new (fMCRec) MCRec(fConservativeRasterClip); |
422 | 402 |
423 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); | 403 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); |
424 fMCRec->fTopLayer = fMCRec->fLayer; | 404 fMCRec->fTopLayer = fMCRec->fLayer; |
425 | 405 |
426 fSurfaceBase = NULL; | 406 fSurfaceBase = NULL; |
427 | 407 |
428 if (device) { | 408 if (device) { |
429 this->setupDevice(device); | |
430 if (device->forceConservativeRasterClip()) { | |
431 fConservativeRasterClip = true; | |
432 } | |
433 device->onAttachToCanvas(this); | 409 device->onAttachToCanvas(this); |
434 fMCRec->fLayer->fDevice = SkRef(device); | 410 fMCRec->fLayer->fDevice = SkRef(device); |
435 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei
ght())); | 411 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei
ght())); |
436 } | 412 } |
437 return device; | 413 return device; |
438 } | 414 } |
439 | 415 |
440 SkCanvas::SkCanvas() | 416 SkCanvas::SkCanvas() |
441 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 417 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
442 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
443 { | 418 { |
444 inc_canvas(); | 419 inc_canvas(); |
445 | 420 |
446 this->init(NULL, kDefault_InitFlags); | 421 this->init(NULL, kDefault_InitFlags); |
447 } | 422 } |
448 | 423 |
449 static SkBitmap make_nopixels(int width, int height) { | 424 static SkBitmap make_nopixels(int width, int height) { |
450 SkBitmap bitmap; | 425 SkBitmap bitmap; |
451 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); | 426 bitmap.setInfo(SkImageInfo::MakeUnknown(width, height)); |
452 return bitmap; | 427 return bitmap; |
453 } | 428 } |
454 | 429 |
455 class SkNoPixelsBitmapDevice : public SkBitmapDevice { | 430 class SkNoPixelsBitmapDevice : public SkBitmapDevice { |
456 public: | 431 public: |
457 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt
h, height)) {} | 432 SkNoPixelsBitmapDevice(int width, int height) : INHERITED(make_nopixels(widt
h, height)) {} |
458 | 433 |
459 private: | 434 private: |
460 | 435 |
461 typedef SkBitmapDevice INHERITED; | 436 typedef SkBitmapDevice INHERITED; |
462 }; | 437 }; |
463 | 438 |
464 SkCanvas::SkCanvas(int width, int height) | 439 SkCanvas::SkCanvas(int width, int height) |
465 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 440 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
466 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
467 { | 441 { |
468 inc_canvas(); | 442 inc_canvas(); |
469 | 443 |
470 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini
tFlags)->unref(); | 444 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), kDefault_Ini
tFlags)->unref(); |
471 } | 445 } |
472 | 446 |
473 SkCanvas::SkCanvas(int width, int height, InitFlags flags) | 447 SkCanvas::SkCanvas(int width, int height, InitFlags flags) |
474 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 448 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
475 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
476 { | 449 { |
477 inc_canvas(); | 450 inc_canvas(); |
478 | 451 |
479 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre
f(); | 452 this->init(SkNEW_ARGS(SkNoPixelsBitmapDevice, (width, height)), flags)->unre
f(); |
480 } | 453 } |
481 | 454 |
482 SkCanvas::SkCanvas(SkBaseDevice* device, const SkSurfaceProps* props, InitFlags
flags) | 455 SkCanvas::SkCanvas(SkBaseDevice* device, InitFlags flags) |
483 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 456 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
484 , fProps(SkSurfacePropsCopyOrDefault(props)) | |
485 { | 457 { |
486 inc_canvas(); | 458 inc_canvas(); |
487 | 459 |
488 this->init(device, flags); | 460 this->init(device, flags); |
489 } | 461 } |
490 | 462 |
491 SkCanvas::SkCanvas(SkBaseDevice* device) | 463 SkCanvas::SkCanvas(SkBaseDevice* device) |
492 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 464 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
493 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
494 { | 465 { |
495 inc_canvas(); | 466 inc_canvas(); |
496 | 467 |
497 this->init(device, kDefault_InitFlags); | 468 this->init(device, kDefault_InitFlags); |
498 } | 469 } |
499 | 470 |
500 SkCanvas::SkCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props) | 471 SkCanvas::SkCanvas(const SkBitmap& bitmap) |
501 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | 472 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) |
502 , fProps(props) | |
503 { | 473 { |
504 inc_canvas(); | 474 inc_canvas(); |
505 | |
506 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); | |
507 this->init(device, kDefault_InitFlags); | |
508 } | |
509 | 475 |
510 SkCanvas::SkCanvas(const SkBitmap& bitmap) | 476 this->init(SkNEW_ARGS(SkBitmapDevice, (bitmap)), kDefault_InitFlags)->unref(
); |
511 : fMCStack(sizeof(MCRec), fMCRecStorage, sizeof(fMCRecStorage)) | |
512 , fProps(SkSurfaceProps::kLegacyFontHost_InitType) | |
513 { | |
514 inc_canvas(); | |
515 | |
516 SkAutoTUnref<SkBaseDevice> device(SkNEW_ARGS(SkBitmapDevice, (bitmap))); | |
517 this->init(device, kDefault_InitFlags); | |
518 } | 477 } |
519 | 478 |
520 SkCanvas::~SkCanvas() { | 479 SkCanvas::~SkCanvas() { |
521 // free up the contents of our deque | 480 // free up the contents of our deque |
522 this->restoreToCount(1); // restore everything but the last | 481 this->restoreToCount(1); // restore everything but the last |
523 SkASSERT(0 == fSaveLayerCount); | 482 SkASSERT(0 == fSaveLayerCount); |
524 | 483 |
525 this->internalRestore(); // restore the last, since we're going away | 484 this->internalRestore(); // restore the last, since we're going away |
526 | 485 |
527 SkDELETE(fMetaData); | 486 SkDELETE(fMetaData); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 557 |
599 if (device) { | 558 if (device) { |
600 device->onAttachToCanvas(this); | 559 device->onAttachToCanvas(this); |
601 } | 560 } |
602 if (rootDevice) { | 561 if (rootDevice) { |
603 rootDevice->onDetachFromCanvas(); | 562 rootDevice->onDetachFromCanvas(); |
604 } | 563 } |
605 | 564 |
606 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); | 565 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); |
607 rootDevice = device; | 566 rootDevice = device; |
608 this->setupDevice(device); | |
609 | 567 |
610 fDeviceCMDirty = true; | 568 fDeviceCMDirty = true; |
611 | 569 |
612 /* Now we update our initial region to have the bounds of the new device, | 570 /* Now we update our initial region to have the bounds of the new device, |
613 and then intersect all of the clips in our stack with these bounds, | 571 and then intersect all of the clips in our stack with these bounds, |
614 to ensure that we can't draw outside of the device's bounds (and trash | 572 to ensure that we can't draw outside of the device's bounds (and trash |
615 memory). | 573 memory). |
616 | 574 |
617 NOTE: this is only a partial-fix, since if the new device is larger than | 575 NOTE: this is only a partial-fix, since if the new device is larger than |
618 the previous one, we don't know how to "enlarge" the clips in our stack, | 576 the previous one, we don't know how to "enlarge" the clips in our stack, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 if (device) { | 892 if (device) { |
935 device = device->createCompatibleDevice(info); | 893 device = device->createCompatibleDevice(info); |
936 } | 894 } |
937 } else { | 895 } else { |
938 device = this->createLayerDevice(info); | 896 device = this->createLayerDevice(info); |
939 } | 897 } |
940 if (NULL == device) { | 898 if (NULL == device) { |
941 SkDebugf("Unable to create device for layer."); | 899 SkDebugf("Unable to create device for layer."); |
942 return count; | 900 return count; |
943 } | 901 } |
944 this->setupDevice(device); | |
945 | 902 |
946 device->setOrigin(ir.fLeft, ir.fTop); | 903 device->setOrigin(ir.fLeft, ir.fTop); |
947 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 904 DeviceCM* layer = SkNEW_ARGS(DeviceCM, |
948 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); | 905 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); |
949 device->unref(); | 906 device->unref(); |
950 | 907 |
951 layer->fNext = fMCRec->fTopLayer; | 908 layer->fNext = fMCRec->fTopLayer; |
952 fMCRec->fLayer = layer; | 909 fMCRec->fLayer = layer; |
953 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 910 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
954 | 911 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 int n = this->getSaveCount() - count; | 987 int n = this->getSaveCount() - count; |
1031 for (int i = 0; i < n; ++i) { | 988 for (int i = 0; i < n; ++i) { |
1032 this->restore(); | 989 this->restore(); |
1033 } | 990 } |
1034 } | 991 } |
1035 | 992 |
1036 bool SkCanvas::isDrawingToLayer() const { | 993 bool SkCanvas::isDrawingToLayer() const { |
1037 return fSaveLayerCount > 0; | 994 return fSaveLayerCount > 0; |
1038 } | 995 } |
1039 | 996 |
1040 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 997 SkSurface* SkCanvas::newSurface(const SkImageInfo& info) { |
1041 if (NULL == props) { | 998 return this->onNewSurface(info); |
1042 props = &fProps; | |
1043 } | |
1044 return this->onNewSurface(info, *props); | |
1045 } | 999 } |
1046 | 1000 |
1047 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info, const SkSurfaceProps&
props) { | 1001 SkSurface* SkCanvas::onNewSurface(const SkImageInfo& info) { |
1048 SkBaseDevice* dev = this->getDevice(); | 1002 SkBaseDevice* dev = this->getDevice(); |
1049 return dev ? dev->newSurface(info, props) : NULL; | 1003 return dev ? dev->newSurface(info) : NULL; |
1050 } | 1004 } |
1051 | 1005 |
1052 SkImageInfo SkCanvas::imageInfo() const { | 1006 SkImageInfo SkCanvas::imageInfo() const { |
1053 SkBaseDevice* dev = this->getDevice(); | 1007 SkBaseDevice* dev = this->getDevice(); |
1054 if (dev) { | 1008 if (dev) { |
1055 return dev->imageInfo(); | 1009 return dev->imageInfo(); |
1056 } else { | 1010 } else { |
1057 return SkImageInfo::MakeUnknown(0, 0); | 1011 return SkImageInfo::MakeUnknown(0, 0); |
1058 } | 1012 } |
1059 } | 1013 } |
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2536 } | 2490 } |
2537 | 2491 |
2538 if (matrix) { | 2492 if (matrix) { |
2539 canvas->concat(*matrix); | 2493 canvas->concat(*matrix); |
2540 } | 2494 } |
2541 } | 2495 } |
2542 | 2496 |
2543 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2497 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2544 fCanvas->restoreToCount(fSaveCount); | 2498 fCanvas->restoreToCount(fSaveCount); |
2545 } | 2499 } |
OLD | NEW |