Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: src/core/SkCanvas.cpp

Issue 920513003: Make filters use SkImage instead of SkBitmap Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "SkImage.h" 16 #include "SkImage.h"
17 #include "SkImagePriv.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"
26 #include "SkTemplates.h" 27 #include "SkTemplates.h"
(...skipping 1143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 } 1171 }
1171 1172
1172 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) 1173 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type)
1173 while (iter.next()) { 1174 while (iter.next()) {
1174 SkBaseDevice* dstDev = iter.fDevice; 1175 SkBaseDevice* dstDev = iter.fDevice;
1175 paint = &looper.paint(); 1176 paint = &looper.paint();
1176 SkImageFilter* filter = paint->getImageFilter(); 1177 SkImageFilter* filter = paint->getImageFilter();
1177 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; 1178 SkIPoint pos = { x - iter.getX(), y - iter.getY() };
1178 if (filter && !dstDev->canHandleImageFilter(filter)) { 1179 if (filter && !dstDev->canHandleImageFilter(filter)) {
1179 SkDeviceImageFilterProxy proxy(dstDev, fProps); 1180 SkDeviceImageFilterProxy proxy(dstDev, fProps);
1180 SkBitmap dst; 1181 SkAutoTUnref<SkImage> dst;
1181 SkIPoint offset = SkIPoint::Make(0, 0); 1182 SkIPoint offset = SkIPoint::Make(0, 0);
1182 const SkBitmap& src = srcDev->accessBitmap(false); 1183 SkAutoTUnref<SkImage> src(srcDev->getSurfaceBase()->newImageSnapshot (SkSurface::kYes_Budgeted));
1183 SkMatrix matrix = *iter.fMatrix; 1184 SkMatrix matrix = *iter.fMatrix;
1184 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() )); 1185 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() ));
1185 SkIRect clipBounds = SkIRect::MakeWH(srcDev->width(), srcDev->height ()); 1186 SkIRect clipBounds = SkIRect::MakeWH(src->width(), src->height());
1186 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache ()); 1187 SkAutoTUnref<SkImageFilter::Cache> cache(dstDev->getImageFilterCache ());
1187 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); 1188 SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
1188 if (filter->filterImage(&proxy, src, ctx, &dst, &offset)) { 1189 if (filter->filterImage(&proxy, *src, ctx, dst, &offset)) {
1189 SkPaint tmpUnfiltered(*paint); 1190 SkPaint tmpUnfiltered(*paint);
1190 tmpUnfiltered.setImageFilter(NULL); 1191 tmpUnfiltered.setImageFilter(NULL);
1191 dstDev->drawSprite(iter, dst, pos.x() + offset.x(), pos.y() + of fset.y(), 1192 dstDev->drawImage(iter, *dst, pos.x() + offset.x(), pos.y() + of fset.y(),
1192 tmpUnfiltered); 1193 tmpUnfiltered);
1193 } 1194 }
1194 } else { 1195 } else {
1195 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint); 1196 dstDev->drawDevice(iter, srcDev, pos.x(), pos.y(), *paint);
1196 } 1197 }
1197 } 1198 }
1198 LOOPER_END 1199 LOOPER_END
1199 } 1200 }
1200 1201
1201 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) { 1202 void SkCanvas::onDrawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint* paint) {
(...skipping 17 matching lines...) Expand all
1219 } 1220 }
1220 1221
1221 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type) 1222 LOOPER_BEGIN_DRAWDEVICE(*paint, SkDrawFilter::kBitmap_Type)
1222 1223
1223 while (iter.next()) { 1224 while (iter.next()) {
1224 paint = &looper.paint(); 1225 paint = &looper.paint();
1225 SkImageFilter* filter = paint->getImageFilter(); 1226 SkImageFilter* filter = paint->getImageFilter();
1226 SkIPoint pos = { x - iter.getX(), y - iter.getY() }; 1227 SkIPoint pos = { x - iter.getX(), y - iter.getY() };
1227 if (filter && !iter.fDevice->canHandleImageFilter(filter)) { 1228 if (filter && !iter.fDevice->canHandleImageFilter(filter)) {
1228 SkDeviceImageFilterProxy proxy(iter.fDevice, fProps); 1229 SkDeviceImageFilterProxy proxy(iter.fDevice, fProps);
1229 SkBitmap dst; 1230 SkAutoTUnref<SkImage> src(SkNewImageFromBitmap(bitmap, false, NULL)) ;
1231 SkAutoTUnref<SkImage> dst;
1230 SkIPoint offset = SkIPoint::Make(0, 0); 1232 SkIPoint offset = SkIPoint::Make(0, 0);
1231 SkMatrix matrix = *iter.fMatrix; 1233 SkMatrix matrix = *iter.fMatrix;
1232 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() )); 1234 matrix.postTranslate(SkIntToScalar(-pos.x()), SkIntToScalar(-pos.y() ));
1233 const SkIRect clipBounds = bitmap.bounds(); 1235 const SkIRect clipBounds = bitmap.bounds();
1234 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte rCache()); 1236 SkAutoTUnref<SkImageFilter::Cache> cache(iter.fDevice->getImageFilte rCache());
1235 SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); 1237 SkImageFilter::Context ctx(matrix, clipBounds, cache.get());
1236 if (filter->filterImage(&proxy, bitmap, ctx, &dst, &offset)) { 1238 if (filter->filterImage(&proxy, *src, ctx, dst, &offset)) {
1237 SkPaint tmpUnfiltered(*paint); 1239 SkPaint tmpUnfiltered(*paint);
1238 tmpUnfiltered.setImageFilter(NULL); 1240 tmpUnfiltered.setImageFilter(NULL);
1239 iter.fDevice->drawSprite(iter, dst, pos.x() + offset.x(), pos.y( ) + offset.y(), 1241 iter.fDevice->drawImage(iter, *dst, pos.x() + offset.x(), pos.y( ) + offset.y(),
1240 tmpUnfiltered); 1242 tmpUnfiltered);
1241 } 1243 }
1242 } else { 1244 } else {
1243 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint); 1245 iter.fDevice->drawSprite(iter, bitmap, pos.x(), pos.y(), *paint);
1244 } 1246 }
1245 } 1247 }
1246 LOOPER_END 1248 LOOPER_END
1247 } 1249 }
1248 1250
1249 ///////////////////////////////////////////////////////////////////////////// 1251 /////////////////////////////////////////////////////////////////////////////
1250 void SkCanvas::translate(SkScalar dx, SkScalar dy) { 1252 void SkCanvas::translate(SkScalar dx, SkScalar dy) {
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 } 2566 }
2565 2567
2566 if (matrix) { 2568 if (matrix) {
2567 canvas->concat(*matrix); 2569 canvas->concat(*matrix);
2568 } 2570 }
2569 } 2571 }
2570 2572
2571 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 2573 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2572 fCanvas->restoreToCount(fSaveCount); 2574 fCanvas->restoreToCount(fSaveCount);
2573 } 2575 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698