| 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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
| 9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 return rec->fLayer->fDevice; | 601 return rec->fLayer->fDevice; |
| 602 } | 602 } |
| 603 | 603 |
| 604 SkBaseDevice* SkCanvas::getTopDevice(bool updateMatrixClip) const { | 604 SkBaseDevice* SkCanvas::getTopDevice(bool updateMatrixClip) const { |
| 605 if (updateMatrixClip) { | 605 if (updateMatrixClip) { |
| 606 const_cast<SkCanvas*>(this)->updateDeviceCMCache(); | 606 const_cast<SkCanvas*>(this)->updateDeviceCMCache(); |
| 607 } | 607 } |
| 608 return fMCRec->fTopLayer->fDevice; | 608 return fMCRec->fTopLayer->fDevice; |
| 609 } | 609 } |
| 610 | 610 |
| 611 SkBaseDevice* SkCanvas::setRootDevice(SkBaseDevice* device) { | |
| 612 // return root device | |
| 613 SkDeque::F2BIter iter(fMCStack); | |
| 614 MCRec* rec = (MCRec*)iter.next(); | |
| 615 SkASSERT(rec && rec->fLayer); | |
| 616 SkBaseDevice* rootDevice = rec->fLayer->fDevice; | |
| 617 | |
| 618 if (rootDevice == device) { | |
| 619 return device; | |
| 620 } | |
| 621 | |
| 622 if (device) { | |
| 623 device->onAttachToCanvas(this); | |
| 624 device->initForRootLayer(fProps.pixelGeometry()); | |
| 625 } | |
| 626 if (rootDevice) { | |
| 627 rootDevice->onDetachFromCanvas(); | |
| 628 } | |
| 629 | |
| 630 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); | |
| 631 rootDevice = device; | |
| 632 | |
| 633 fDeviceCMDirty = true; | |
| 634 | |
| 635 /* Now we update our initial region to have the bounds of the new device, | |
| 636 and then intersect all of the clips in our stack with these bounds, | |
| 637 to ensure that we can't draw outside of the device's bounds (and trash | |
| 638 memory). | |
| 639 | |
| 640 NOTE: this is only a partial-fix, since if the new device is larger than | |
| 641 the previous one, we don't know how to "enlarge" the clips in our stack, | |
| 642 so drawing may be artificially restricted. Without keeping a history of | |
| 643 all calls to canvas->clipRect() and canvas->clipPath(), we can't exactly | |
| 644 reconstruct the correct clips, so this approximation will have to do. | |
| 645 The caller really needs to restore() back to the base if they want to | |
| 646 accurately take advantage of the new device bounds. | |
| 647 */ | |
| 648 | |
| 649 SkIRect bounds; | |
| 650 if (device) { | |
| 651 bounds.set(0, 0, device->width(), device->height()); | |
| 652 } else { | |
| 653 bounds.setEmpty(); | |
| 654 } | |
| 655 // now jam our 1st clip to be bounds, and intersect the rest with that | |
| 656 rec->fRasterClip.setRect(bounds); | |
| 657 while ((rec = (MCRec*)iter.next()) != NULL) { | |
| 658 (void)rec->fRasterClip.op(bounds, SkRegion::kIntersect_Op); | |
| 659 } | |
| 660 | |
| 661 return device; | |
| 662 } | |
| 663 | |
| 664 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { | 611 bool SkCanvas::readPixels(SkBitmap* bitmap, int x, int y) { |
| 665 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) { | 612 if (kUnknown_SkColorType == bitmap->colorType() || bitmap->getTexture()) { |
| 666 return false; | 613 return false; |
| 667 } | 614 } |
| 668 | 615 |
| 669 bool weAllocated = false; | 616 bool weAllocated = false; |
| 670 if (NULL == bitmap->pixelRef()) { | 617 if (NULL == bitmap->pixelRef()) { |
| 671 if (!bitmap->tryAllocPixels()) { | 618 if (!bitmap->tryAllocPixels()) { |
| 672 return false; | 619 return false; |
| 673 } | 620 } |
| (...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2564 } | 2511 } |
| 2565 | 2512 |
| 2566 if (matrix) { | 2513 if (matrix) { |
| 2567 canvas->concat(*matrix); | 2514 canvas->concat(*matrix); |
| 2568 } | 2515 } |
| 2569 } | 2516 } |
| 2570 | 2517 |
| 2571 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2518 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
| 2572 fCanvas->restoreToCount(fSaveCount); | 2519 fCanvas->restoreToCount(fSaveCount); |
| 2573 } | 2520 } |
| OLD | NEW |