| 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 |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); | 868 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, kARGB_ClipLa
yer_SaveFlag); |
| 869 return this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, fals
e, strategy); | 869 return this->internalSaveLayer(bounds, paint, kARGB_ClipLayer_SaveFlag, fals
e, strategy); |
| 870 } | 870 } |
| 871 | 871 |
| 872 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, | 872 int SkCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 873 SaveFlags flags) { | 873 SaveFlags flags) { |
| 874 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); | 874 SaveLayerStrategy strategy = this->willSaveLayer(bounds, paint, flags); |
| 875 return this->internalSaveLayer(bounds, paint, flags, false, strategy); | 875 return this->internalSaveLayer(bounds, paint, flags, false, strategy); |
| 876 } | 876 } |
| 877 | 877 |
| 878 static SkBaseDevice* create_compatible_device(SkCanvas* canvas, | |
| 879 const SkImageInfo& info) { | |
| 880 SkBaseDevice* device = canvas->getDevice(); | |
| 881 return device ? device->createCompatibleDevice(info) : NULL; | |
| 882 } | |
| 883 | |
| 884 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save
Flags flags, | 878 int SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Save
Flags flags, |
| 885 bool justForImageFilter, SaveLayerStrategy strat
egy) { | 879 bool justForImageFilter, SaveLayerStrategy strat
egy) { |
| 886 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 880 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
| 887 flags |= kClipToLayer_SaveFlag; | 881 flags |= kClipToLayer_SaveFlag; |
| 888 #endif | 882 #endif |
| 889 | 883 |
| 890 // do this before we create the layer. We don't call the public save() since | 884 // do this before we create the layer. We don't call the public save() since |
| 891 // that would invoke a possibly overridden virtual | 885 // that would invoke a possibly overridden virtual |
| 892 int count = this->internalSave(flags); | 886 int count = this->internalSave(flags); |
| 893 | 887 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 917 paint = p; | 911 paint = p; |
| 918 } | 912 } |
| 919 } | 913 } |
| 920 | 914 |
| 921 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); | 915 bool isOpaque = !SkToBool(flags & kHasAlphaLayer_SaveFlag); |
| 922 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), | 916 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(), |
| 923 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 917 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 924 | 918 |
| 925 SkBaseDevice* device; | 919 SkBaseDevice* device; |
| 926 if (paint && paint->getImageFilter()) { | 920 if (paint && paint->getImageFilter()) { |
| 927 device = create_compatible_device(this, info); | 921 device = this->getDevice(); |
| 922 if (device) { |
| 923 device = device->createCompatibleDevice(info); |
| 924 } |
| 928 } else { | 925 } else { |
| 929 device = this->createLayerDevice(info); | 926 device = this->createLayerDevice(info); |
| 930 } | 927 } |
| 931 if (NULL == device) { | 928 if (NULL == device) { |
| 932 SkDebugf("Unable to create device for layer."); | 929 SkDebugf("Unable to create device for layer."); |
| 933 return count; | 930 return count; |
| 934 } | 931 } |
| 935 | 932 |
| 936 device->setOrigin(ir.fLeft, ir.fTop); | 933 device->setOrigin(ir.fLeft, ir.fTop); |
| 937 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, ir.fLeft, ir.fTop, paint, th
is)); | 934 DeviceCM* layer = SkNEW_ARGS(DeviceCM, (device, ir.fLeft, ir.fTop, paint, th
is)); |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 // but relaxing the test above triggers GM asserts in | 1392 // but relaxing the test above triggers GM asserts in |
| 1396 // SkRgnBuilder::blitH(). We need to investigate what's going on. | 1393 // SkRgnBuilder::blitH(). We need to investigate what's going on. |
| 1397 currClip->setPath(devPath, currClip->bwRgn(), doAA); | 1394 currClip->setPath(devPath, currClip->bwRgn(), doAA); |
| 1398 } else { | 1395 } else { |
| 1399 base.setRect(currClip->getBounds()); | 1396 base.setRect(currClip->getBounds()); |
| 1400 SkRasterClip clip; | 1397 SkRasterClip clip; |
| 1401 clip.setPath(devPath, base, doAA); | 1398 clip.setPath(devPath, base, doAA); |
| 1402 currClip->op(clip, op); | 1399 currClip->op(clip, op); |
| 1403 } | 1400 } |
| 1404 } else { | 1401 } else { |
| 1405 const SkBaseDevice* device = canvas->getDevice(); | 1402 const SkISize size = canvas->getBaseLayerSize(); |
| 1406 if (!device) { | 1403 base.setRect(0, 0, size.width(), size.height()); |
| 1407 currClip->setEmpty(); | |
| 1408 return; | |
| 1409 } | |
| 1410 | |
| 1411 base.setRect(0, 0, device->width(), device->height()); | |
| 1412 | 1404 |
| 1413 if (SkRegion::kReplace_Op == op) { | 1405 if (SkRegion::kReplace_Op == op) { |
| 1414 currClip->setPath(devPath, base, doAA); | 1406 currClip->setPath(devPath, base, doAA); |
| 1415 } else { | 1407 } else { |
| 1416 SkRasterClip clip; | 1408 SkRasterClip clip; |
| 1417 clip.setPath(devPath, base, doAA); | 1409 clip.setPath(devPath, base, doAA); |
| 1418 currClip->op(clip, op); | 1410 currClip->op(clip, op); |
| 1419 } | 1411 } |
| 1420 } | 1412 } |
| 1421 } | 1413 } |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2585 if (!supported_for_raster_canvas(info)) { | 2577 if (!supported_for_raster_canvas(info)) { |
| 2586 return NULL; | 2578 return NULL; |
| 2587 } | 2579 } |
| 2588 | 2580 |
| 2589 SkBitmap bitmap; | 2581 SkBitmap bitmap; |
| 2590 if (!bitmap.installPixels(info, pixels, rowBytes)) { | 2582 if (!bitmap.installPixels(info, pixels, rowBytes)) { |
| 2591 return NULL; | 2583 return NULL; |
| 2592 } | 2584 } |
| 2593 return SkNEW_ARGS(SkCanvas, (bitmap)); | 2585 return SkNEW_ARGS(SkCanvas, (bitmap)); |
| 2594 } | 2586 } |
| OLD | NEW |