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" |
11 #include "SkDeviceImageFilterProxy.h" | 11 #include "SkDeviceImageFilterProxy.h" |
12 #include "SkDraw.h" | 12 #include "SkDraw.h" |
13 #include "SkDrawable.h" | 13 #include "SkDrawable.h" |
14 #include "SkDrawFilter.h" | 14 #include "SkDrawFilter.h" |
15 #include "SkDrawLooper.h" | 15 #include "SkDrawLooper.h" |
| 16 #include "SkImagePriv.h" |
16 #include "SkImage_Base.h" | 17 #include "SkImage_Base.h" |
17 #include "SkMetaData.h" | 18 #include "SkMetaData.h" |
18 #include "SkPathOps.h" | 19 #include "SkPathOps.h" |
19 #include "SkPatchUtils.h" | 20 #include "SkPatchUtils.h" |
20 #include "SkPicture.h" | 21 #include "SkPicture.h" |
21 #include "SkRasterClip.h" | 22 #include "SkRasterClip.h" |
22 #include "SkReadPixelsRec.h" | 23 #include "SkReadPixelsRec.h" |
23 #include "SkRRect.h" | 24 #include "SkRRect.h" |
24 #include "SkSmallAllocator.h" | 25 #include "SkSmallAllocator.h" |
25 #include "SkSurface_Base.h" | 26 #include "SkSurface_Base.h" |
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 } | 1104 } |
1104 | 1105 |
1105 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1106 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
1106 while (iter.next()) { | 1107 while (iter.next()) { |
1107 SkBaseDevice* dstDev = iter.fDevice; | 1108 SkBaseDevice* dstDev = iter.fDevice; |
1108 paint = &looper.paint(); | 1109 paint = &looper.paint(); |
1109 SkImageFilter* filter = paint->getImageFilter(); | 1110 SkImageFilter* filter = paint->getImageFilter(); |
1110 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | 1111 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
1111 if (filter && !dstDev->canHandleImageFilter(filter)) { | 1112 if (filter && !dstDev->canHandleImageFilter(filter)) { |
1112 SkDeviceImageFilterProxy proxy(dstDev, fProps); | 1113 SkDeviceImageFilterProxy proxy(dstDev, fProps); |
1113 SkBitmap dst; | 1114 SkAutoTUnref<const SkImage> dst; |
1114 SkIPoint offset = SkIPoint::Make(0, 0); | 1115 SkIPoint offset = SkIPoint::Make(0, 0); |
1115 SkAutoTUnref<SkImage> src(srcDev->newImageSnapshot()); | 1116 SkAutoTUnref<SkImage> src(srcDev->newImageSnapshot()); |
1116 SkMatrix matrix = *iter.fMatrix; | 1117 SkMatrix matrix = *iter.fMatrix; |
1117 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()
)); | 1118 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()
)); |
1118 SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height
()); | 1119 SkIRect clipBounds = SkIRect::MakeWH(src->width(), src->height()); |
1119 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache
()); | 1120 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache
()); |
1120 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); | 1121 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
1121 SkBitmap srcBitmap; // TODO: remove once filters accept SkImage | 1122 if (filter->filterImage(&proxy, src, ctx, dst, &offset)) { |
1122 #if SK_SUPPORT_GPU | 1123 SkPaint tmpUnfiltered(*paint); |
1123 // TODO: Gpu devices need bitmap that came from gpu, not through | 1124 tmpUnfiltered.setImageFilter(NULL); |
1124 // getROPixels. Remove once filters accept SkImage. | 1125 dstDev->drawSprite(iter, *dst, pos.x() + offset.x(), pos.y() + o
ffset.y(), |
1125 if (NULL != src->getTexture()) { | 1126 tmpUnfiltered); |
1126 SkImageFilter::WrapTexture(src->getTexture(), src->width(), src-
>height(), | |
1127 &srcBitmap); | |
1128 } else | |
1129 #endif | |
1130 { | |
1131 as_IB(src)->getROPixels(&srcBitmap); | |
1132 } | |
1133 if (!srcBitmap.empty()) { | |
1134 if (filter->filterImage(&proxy, srcBitmap, ctx, &dst, &offset))
{ | |
1135 SkPaint tmpUnfiltered(*paint); | |
1136 tmpUnfiltered.setImageFilter(NULL); | |
1137 dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y()
+ offset.y(), | |
1138 tmpUnfiltered); | |
1139 } | |
1140 } | 1127 } |
1141 } else { | 1128 } else { |
1142 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); | 1129 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); |
1143 } | 1130 } |
1144 } | 1131 } |
1145 LOOPER_END | 1132 LOOPER_END |
1146 } | 1133 } |
1147 | 1134 |
1148 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint*
paint) { | 1135 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint*
paint) { |
1149 if (gTreatSpriteAsBitmap) { | 1136 if (gTreatSpriteAsBitmap) { |
(...skipping 16 matching lines...) Expand all Loading... |
1166 } | 1153 } |
1167 | 1154 |
1168 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) | 1155 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) |
1169 | 1156 |
1170 while (iter.next()) { | 1157 while (iter.next()) { |
1171 paint = &looper.paint(); | 1158 paint = &looper.paint(); |
1172 SkImageFilter* filter = paint->getImageFilter(); | 1159 SkImageFilter* filter = paint->getImageFilter(); |
1173 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; | 1160 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
1174 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { | 1161 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { |
1175 SkDeviceImageFilterProxy proxy(iter.fDevice, fProps); | 1162 SkDeviceImageFilterProxy proxy(iter.fDevice, fProps); |
1176 SkBitmap dst; | 1163 SkAutoTUnref<SkImage> src(SkNewImageFromBitmap(bitmap, NULL)); |
| 1164 SkAutoTUnref<const SkImage> dst; |
1177 SkIPoint offset = SkIPoint::Make(0, 0); | 1165 SkIPoint offset = SkIPoint::Make(0, 0); |
1178 SkMatrix matrix = *iter.fMatrix; | 1166 SkMatrix matrix = *iter.fMatrix; |
1179 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()
)); | 1167 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()
)); |
1180 const SkIRect clipBounds = bitmap.bounds(); | 1168 const SkIRect clipBounds = bitmap.bounds(); |
1181 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte
rCache()); | 1169 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte
rCache()); |
1182 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); | 1170 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
1183 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { | 1171 if (filter->filterImage(&proxy, src, ctx, dst, &offset)) { |
1184 SkPaint tmpUnfiltered(*paint); | 1172 SkPaint tmpUnfiltered(*paint); |
1185 tmpUnfiltered.setImageFilter(NULL); | 1173 tmpUnfiltered.setImageFilter(NULL); |
1186 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y(
) + offset.y(), | 1174 iter.fDevice->drawSprite(iter, *dst, pos.x() + offset.x(), |
1187 tmpUnfiltered); | 1175 pos.y() + offset.y(), tmpUnfiltered); |
1188 } | 1176 } |
1189 } else { | 1177 } else { |
1190 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); | 1178 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); |
1191 } | 1179 } |
1192 } | 1180 } |
1193 LOOPER_END | 1181 LOOPER_END |
1194 } | 1182 } |
1195 | 1183 |
| 1184 void SkCanvas::onDrawSprite(const SkImage& image, int x, int y, const SkPaint* p
aint) { |
| 1185 if (gTreatSpriteAsBitmap) { |
| 1186 this->save(); |
| 1187 this->resetMatrix(); |
| 1188 this->drawImage(&image, SkIntToScalar(x), SkIntToScalar(y), paint); |
| 1189 this->restore(); |
| 1190 return; |
| 1191 } |
| 1192 |
| 1193 TRACE_EVENT0("disabled-by-default-skia", "SkCanvas::drawSprite()"); |
| 1194 |
| 1195 SkPaint tmp; |
| 1196 if (NULL == paint) { |
| 1197 paint = &tmp; |
| 1198 } |
| 1199 |
| 1200 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kImage_Type) |
| 1201 |
| 1202 while (iter.next()) { |
| 1203 paint = &looper.paint(); |
| 1204 SkImageFilter* filter = paint->getImageFilter(); |
| 1205 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; |
| 1206 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { |
| 1207 SkDeviceImageFilterProxy proxy(iter.fDevice, fProps); |
| 1208 SkAutoTUnref<const SkImage> dst; |
| 1209 SkIPoint offset = SkIPoint::Make(0, 0); |
| 1210 SkMatrix matrix = *iter.fMatrix; |
| 1211 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y()
)); |
| 1212 const SkIRect clipBounds = SkIRect::MakeWH(image.width(), image.heig
ht()); |
| 1213 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte
rCache()); |
| 1214 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); |
| 1215 if (filter->filterImage(&proxy, &image, ctx, dst, &offset)) { |
| 1216 SkPaint tmpUnfiltered(*paint); |
| 1217 tmpUnfiltered.setImageFilter(NULL); |
| 1218 iter.fDevice->drawSprite(iter, *dst, pos.x() + offset.x(), |
| 1219 pos.y() + offset.y(), tmpUnfiltered); |
| 1220 } |
| 1221 } else { |
| 1222 iter.fDevice->drawSprite(iter, image, pos.x(), pos.y(), *paint); |
| 1223 } |
| 1224 } |
| 1225 LOOPER_END |
| 1226 } |
| 1227 |
1196 ///////////////////////////////////////////////////////////////////////////// | 1228 ///////////////////////////////////////////////////////////////////////////// |
1197 void SkCanvas::translate(SkScalar dx, SkScalar dy) { | 1229 void SkCanvas::translate(SkScalar dx, SkScalar dy) { |
1198 SkMatrix m; | 1230 SkMatrix m; |
1199 m.setTranslate(dx, dy); | 1231 m.setTranslate(dx, dy); |
1200 this->concat(m); | 1232 this->concat(m); |
1201 } | 1233 } |
1202 | 1234 |
1203 void SkCanvas::scale(SkScalar sx, SkScalar sy) { | 1235 void SkCanvas::scale(SkScalar sx, SkScalar sy) { |
1204 SkMatrix m; | 1236 SkMatrix m; |
1205 m.setScale(sx, sy); | 1237 m.setScale(sx, sy); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1652 } | 1684 } |
1653 | 1685 |
1654 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, | 1686 void SkCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, con
st SkRect& dst, |
1655 const SkPaint* paint) { | 1687 const SkPaint* paint) { |
1656 this->onDrawBitmapNine(bitmap, center, dst, paint); | 1688 this->onDrawBitmapNine(bitmap, center, dst, paint); |
1657 } | 1689 } |
1658 | 1690 |
1659 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai
nt* paint) { | 1691 void SkCanvas::drawSprite(const SkBitmap& bitmap, int left, int top, const SkPai
nt* paint) { |
1660 this->onDrawSprite(bitmap, left, top, paint); | 1692 this->onDrawSprite(bitmap, left, top, paint); |
1661 } | 1693 } |
| 1694 void SkCanvas::drawSprite(const SkImage& image, int left, int top, const SkPaint
* paint) { |
| 1695 this->onDrawSprite(image, left, top, paint); |
| 1696 } |
1662 | 1697 |
1663 ////////////////////////////////////////////////////////////////////////////// | 1698 ////////////////////////////////////////////////////////////////////////////// |
1664 // These are the virtual drawing methods | 1699 // These are the virtual drawing methods |
1665 ////////////////////////////////////////////////////////////////////////////// | 1700 ////////////////////////////////////////////////////////////////////////////// |
1666 | 1701 |
1667 void SkCanvas::onDiscard() { | 1702 void SkCanvas::onDiscard() { |
1668 if (NULL != this->getDevice()) { | 1703 if (NULL != this->getDevice()) { |
1669 this->getDevice()->discard(); | 1704 this->getDevice()->discard(); |
1670 } | 1705 } |
1671 } | 1706 } |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2511 } | 2546 } |
2512 | 2547 |
2513 if (matrix) { | 2548 if (matrix) { |
2514 canvas->concat(*matrix); | 2549 canvas->concat(*matrix); |
2515 } | 2550 } |
2516 } | 2551 } |
2517 | 2552 |
2518 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 2553 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
2519 fCanvas->restoreToCount(fSaveCount); | 2554 fCanvas->restoreToCount(fSaveCount); |
2520 } | 2555 } |
OLD | NEW |