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