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 "SkCanvasDrawable.h" | 9 #include "SkCanvasDrawable.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 #define LOOPER_BEGIN(paint, type, bounds) \ | 398 #define LOOPER_BEGIN(paint, type, bounds) \ |
399 this->predrawNotify(); \ | 399 this->predrawNotify(); \ |
400 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ | 400 AutoDrawLooper looper(this, fProps, paint, false, bounds); \ |
401 while (looper.next(type)) { \ | 401 while (looper.next(type)) { \ |
402 SkDrawIter iter(this); | 402 SkDrawIter iter(this); |
403 | 403 |
404 #define LOOPER_END } | 404 #define LOOPER_END } |
405 | 405 |
406 //////////////////////////////////////////////////////////////////////////// | 406 //////////////////////////////////////////////////////////////////////////// |
407 | 407 |
408 void SkCanvas::setupDevice(SkBaseDevice* device) { | |
409 device->setPixelGeometry(fProps.pixelGeometry()); | |
410 } | |
411 | |
412 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { | 408 SkBaseDevice* SkCanvas::init(SkBaseDevice* device, InitFlags flags) { |
413 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; | 409 fConservativeRasterClip = SkToBool(flags & kConservativeRasterClip_InitFlag)
; |
414 fCachedLocalClipBounds.setEmpty(); | 410 fCachedLocalClipBounds.setEmpty(); |
415 fCachedLocalClipBoundsDirty = true; | 411 fCachedLocalClipBoundsDirty = true; |
416 fAllowSoftClip = true; | 412 fAllowSoftClip = true; |
417 fAllowSimplifyClip = false; | 413 fAllowSimplifyClip = false; |
418 fDeviceCMDirty = true; | 414 fDeviceCMDirty = true; |
419 fSaveLayerCount = 0; | 415 fSaveLayerCount = 0; |
420 fCullCount = 0; | 416 fCullCount = 0; |
421 fMetaData = NULL; | 417 fMetaData = NULL; |
422 | 418 |
423 fMCRec = (MCRec*)fMCStack.push_back(); | 419 fMCRec = (MCRec*)fMCStack.push_back(); |
424 new (fMCRec) MCRec(fConservativeRasterClip); | 420 new (fMCRec) MCRec(fConservativeRasterClip); |
425 | 421 |
426 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); | 422 fMCRec->fLayer = SkNEW_ARGS(DeviceCM, (NULL, 0, 0, NULL, NULL, fConservative
RasterClip)); |
427 fMCRec->fTopLayer = fMCRec->fLayer; | 423 fMCRec->fTopLayer = fMCRec->fLayer; |
428 | 424 |
429 fSurfaceBase = NULL; | 425 fSurfaceBase = NULL; |
430 | 426 |
431 if (device) { | 427 if (device) { |
432 this->setupDevice(device); | 428 device->initForRootLayer(fProps.pixelGeometry()); |
433 if (device->forceConservativeRasterClip()) { | 429 if (device->forceConservativeRasterClip()) { |
434 fConservativeRasterClip = true; | 430 fConservativeRasterClip = true; |
435 } | 431 } |
436 device->onAttachToCanvas(this); | 432 device->onAttachToCanvas(this); |
437 fMCRec->fLayer->fDevice = SkRef(device); | 433 fMCRec->fLayer->fDevice = SkRef(device); |
438 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei
ght())); | 434 fMCRec->fRasterClip.setRect(SkIRect::MakeWH(device->width(), device->hei
ght())); |
439 } | 435 } |
440 return device; | 436 return device; |
441 } | 437 } |
442 | 438 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 MCRec* rec = (MCRec*)iter.next(); | 590 MCRec* rec = (MCRec*)iter.next(); |
595 SkASSERT(rec && rec->fLayer); | 591 SkASSERT(rec && rec->fLayer); |
596 SkBaseDevice* rootDevice = rec->fLayer->fDevice; | 592 SkBaseDevice* rootDevice = rec->fLayer->fDevice; |
597 | 593 |
598 if (rootDevice == device) { | 594 if (rootDevice == device) { |
599 return device; | 595 return device; |
600 } | 596 } |
601 | 597 |
602 if (device) { | 598 if (device) { |
603 device->onAttachToCanvas(this); | 599 device->onAttachToCanvas(this); |
| 600 device->initForRootLayer(fProps.pixelGeometry()); |
604 } | 601 } |
605 if (rootDevice) { | 602 if (rootDevice) { |
606 rootDevice->onDetachFromCanvas(); | 603 rootDevice->onDetachFromCanvas(); |
607 } | 604 } |
608 | 605 |
609 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); | 606 SkRefCnt_SafeAssign(rec->fLayer->fDevice, device); |
610 rootDevice = device; | 607 rootDevice = device; |
611 this->setupDevice(device); | |
612 | 608 |
613 fDeviceCMDirty = true; | 609 fDeviceCMDirty = true; |
614 | 610 |
615 /* Now we update our initial region to have the bounds of the new device, | 611 /* Now we update our initial region to have the bounds of the new device, |
616 and then intersect all of the clips in our stack with these bounds, | 612 and then intersect all of the clips in our stack with these bounds, |
617 to ensure that we can't draw outside of the device's bounds (and trash | 613 to ensure that we can't draw outside of the device's bounds (and trash |
618 memory). | 614 memory). |
619 | 615 |
620 NOTE: this is only a partial-fix, since if the new device is larger than | 616 NOTE: this is only a partial-fix, since if the new device is larger than |
621 the previous one, we don't know how to "enlarge" the clips in our stack, | 617 the previous one, we don't know how to "enlarge" the clips in our stack, |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 SkPaint* p = lazyP.set(*paint); | 920 SkPaint* p = lazyP.set(*paint); |
925 p->setImageFilter(NULL); | 921 p->setImageFilter(NULL); |
926 paint = p; | 922 paint = p; |
927 } | 923 } |
928 } | 924 } |
929 | 925 |
930 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 926 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
931 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), | 927 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
932 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 928 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
933 | 929 |
934 SkBaseDevice* device; | 930 SkBaseDevice* device = this->getTopDevice(); |
| 931 if (NULL == device) { |
| 932 SkDebugf("Unable to find device for layer."); |
| 933 return count; |
| 934 } |
| 935 |
| 936 SkBaseDevice::Usage usage = SkBaseDevice::kSaveLayer_Usage; |
935 if (paint && paint->getImageFilter()) { | 937 if (paint && paint->getImageFilter()) { |
936 device = this->getDevice(); | 938 usage = SkBaseDevice::kImageFilter_Usage; |
937 if (device) { | |
938 device = device->createCompatibleDeviceForImageFilter(info); | |
939 } | |
940 } else { | |
941 device = this->createLayerDevice(info); | |
942 } | 939 } |
| 940 device = device->onCreateCompatibleDevice(SkBaseDevice::CreateInfo(info, usa
ge, |
| 941 fProps.pi
xelGeometry())); |
943 if (NULL == device) { | 942 if (NULL == device) { |
944 SkDebugf("Unable to create device for layer."); | 943 SkDebugf("Unable to create device for layer."); |
945 return count; | 944 return count; |
946 } | 945 } |
947 this->setupDevice(device); | |
948 | 946 |
949 device->setOrigin(ir.fLeft, ir.fTop); | 947 device->setOrigin(ir.fLeft, ir.fTop); |
950 DeviceCM* layer = SkNEW_ARGS(DeviceCM, | 948 DeviceCM* layer = SkNEW_ARGS(DeviceCM, |
951 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); | 949 (device, ir.fLeft, ir.fTop, paint, this, fConse
rvativeRasterClip)); |
952 device->unref(); | 950 device->unref(); |
953 | 951 |
954 layer->fNext = fMCRec->fTopLayer; | 952 layer->fNext = fMCRec->fTopLayer; |
955 fMCRec->fLayer = layer; | 953 fMCRec->fLayer = layer; |
956 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 954 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
957 | 955 |
(...skipping 700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 | 1656 |
1659 const SkRegion& SkCanvas::internal_private_getTotalClip() const { | 1657 const SkRegion& SkCanvas::internal_private_getTotalClip() const { |
1660 return fMCRec->fRasterClip.forceGetBW(); | 1658 return fMCRec->fRasterClip.forceGetBW(); |
1661 } | 1659 } |
1662 | 1660 |
1663 GrRenderTarget* SkCanvas::internal_private_accessTopLayerRenderTarget() { | 1661 GrRenderTarget* SkCanvas::internal_private_accessTopLayerRenderTarget() { |
1664 SkBaseDevice* dev = this->getTopDevice(); | 1662 SkBaseDevice* dev = this->getTopDevice(); |
1665 return dev ? dev->accessRenderTarget() : NULL; | 1663 return dev ? dev->accessRenderTarget() : NULL; |
1666 } | 1664 } |
1667 | 1665 |
1668 SkBaseDevice* SkCanvas::createLayerDevice(const SkImageInfo& info) { | |
1669 SkBaseDevice* device = this->getTopDevice(); | |
1670 return device ? device->createCompatibleDeviceForSaveLayer(info) : NULL; | |
1671 } | |
1672 | |
1673 GrContext* SkCanvas::getGrContext() { | 1666 GrContext* SkCanvas::getGrContext() { |
1674 #if SK_SUPPORT_GPU | 1667 #if SK_SUPPORT_GPU |
1675 SkBaseDevice* device = this->getTopDevice(); | 1668 SkBaseDevice* device = this->getTopDevice(); |
1676 if (device) { | 1669 if (device) { |
1677 GrRenderTarget* renderTarget = device->accessRenderTarget(); | 1670 GrRenderTarget* renderTarget = device->accessRenderTarget(); |
1678 if (renderTarget) { | 1671 if (renderTarget) { |
1679 return renderTarget->getContext(); | 1672 return renderTarget->getContext(); |
1680 } | 1673 } |
1681 } | 1674 } |
1682 #endif | 1675 #endif |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 TRACE_EVENT0("skia", "SkCanvas::drawBitmapNine()"); | 2048 TRACE_EVENT0("skia", "SkCanvas::drawBitmapNine()"); |
2056 SkDEBUGCODE(bitmap.validate();) | 2049 SkDEBUGCODE(bitmap.validate();) |
2057 | 2050 |
2058 // Need a device entry-point, so gpu can use a mesh | 2051 // Need a device entry-point, so gpu can use a mesh |
2059 this->internalDrawBitmapNine(bitmap, center, dst, paint); | 2052 this->internalDrawBitmapNine(bitmap, center, dst, paint); |
2060 } | 2053 } |
2061 | 2054 |
2062 class SkDeviceFilteredPaint { | 2055 class SkDeviceFilteredPaint { |
2063 public: | 2056 public: |
2064 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { | 2057 SkDeviceFilteredPaint(SkBaseDevice* device, const SkPaint& paint) { |
2065 SkBaseDevice::TextFlags flags; | 2058 if (device->shouldDisableLCD(paint)) { |
2066 if (device->filterTextFlags(paint, &flags)) { | 2059 uint32_t flags = paint.getFlags(); |
| 2060 flags &= ~SkPaint::kLCDRenderText_Flag; |
| 2061 flags |= SkPaint::kGenA8FromLCD_Flag; |
2067 SkPaint* newPaint = fLazy.set(paint); | 2062 SkPaint* newPaint = fLazy.set(paint); |
2068 newPaint->setFlags(flags.fFlags); | 2063 newPaint->setFlags(flags); |
2069 fPaint = newPaint; | 2064 fPaint = newPaint; |
2070 } else { | 2065 } else { |
2071 fPaint = &paint; | 2066 fPaint = &paint; |
2072 } | 2067 } |
2073 } | 2068 } |
2074 | 2069 |
2075 const SkPaint& paint() const { return *fPaint; } | 2070 const SkPaint& paint() const { return *fPaint; } |
2076 | 2071 |
2077 private: | 2072 private: |
2078 const SkPaint* fPaint; | 2073 const SkPaint* fPaint; |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2591 } | 2586 } |
2592 | 2587 |
2593 if (matrix) { | 2588 if (matrix) { |
2594 canvas->concat(*matrix); | 2589 canvas->concat(*matrix); |
2595 } | 2590 } |
2596 } | 2591 } |
2597 | 2592 |
2598 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2593 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2599 fCanvas->restoreToCount(fSaveCount); | 2594 fCanvas->restoreToCount(fSaveCount); |
2600 } | 2595 } |
OLD | NEW |