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

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

Issue 1685203002: lots of sRGB and F16 blits (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use SkAutoTMalloc Created 4 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
« no previous file with comments | « src/core/SkBlitter_Sprite.cpp ('k') | src/core/SkSpanProcs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBitmapDevice.h" 8 #include "SkBitmapDevice.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkCanvasPriv.h" 10 #include "SkCanvasPriv.h"
(...skipping 1149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 SkCanvas c(dst); 1160 SkCanvas c(dst);
1161 1161
1162 SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm)); 1162 SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm));
1163 SkPaint p; 1163 SkPaint p;
1164 p.setImageFilter(localF); 1164 p.setImageFilter(localF);
1165 const SkScalar x = SkIntToScalar(src->getOrigin().x()); 1165 const SkScalar x = SkIntToScalar(src->getOrigin().x());
1166 const SkScalar y = SkIntToScalar(src->getOrigin().y()); 1166 const SkScalar y = SkIntToScalar(src->getOrigin().y());
1167 c.drawBitmap(srcBM, x, y, &p); 1167 c.drawBitmap(srcBM, x, y, &p);
1168 } 1168 }
1169 1169
1170 static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i sOpaque,
1171 const SkPaint* paint) {
1172 // need to force L32 for now if we have an image filter. Once filters suppor t other colortypes
1173 // e.g. sRGB or F16, we can remove this check
1174 const bool hasImageFilter = paint && paint->getImageFilter();
1175
1176 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType ;
1177 if ((prev.bytesPerPixel() < 4) || hasImageFilter) {
1178 // force to L32
1179 return SkImageInfo::MakeN32(w, h, alphaType);
1180 } else {
1181 // keep the same characteristics as the prev
1182 return SkImageInfo::Make(w, h, prev.colorType(), alphaType, prev.profile Type());
1183 }
1184 }
1185
1170 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) { 1186 void SkCanvas::internalSaveLayer(const SaveLayerRec& rec, SaveLayerStrategy stra tegy) {
1171 const SkRect* bounds = rec.fBounds; 1187 const SkRect* bounds = rec.fBounds;
1172 const SkPaint* paint = rec.fPaint; 1188 const SkPaint* paint = rec.fPaint;
1173 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags; 1189 SaveLayerFlags saveLayerFlags = rec.fSaveLayerFlags;
1174 1190
1175 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG 1191 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG
1176 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag; 1192 saveLayerFlags &= ~kDontClipToLayer_PrivateSaveLayerFlag;
1177 #endif 1193 #endif
1178 1194
1179 // do this before we create the layer. We don't call the public save() since 1195 // do this before we create the layer. We don't call the public save() since
(...skipping 15 matching lines...) Expand all
1195 1211
1196 bool isOpaque = SkToBool(saveLayerFlags & kIsOpaque_SaveLayerFlag); 1212 bool isOpaque = SkToBool(saveLayerFlags & kIsOpaque_SaveLayerFlag);
1197 SkPixelGeometry geo = fProps.pixelGeometry(); 1213 SkPixelGeometry geo = fProps.pixelGeometry();
1198 if (paint) { 1214 if (paint) {
1199 // TODO: perhaps add a query to filters so we might preserve opaqueness. .. 1215 // TODO: perhaps add a query to filters so we might preserve opaqueness. ..
1200 if (paint->getImageFilter() || paint->getColorFilter()) { 1216 if (paint->getImageFilter() || paint->getColorFilter()) {
1201 isOpaque = false; 1217 isOpaque = false;
1202 geo = kUnknown_SkPixelGeometry; 1218 geo = kUnknown_SkPixelGeometry;
1203 } 1219 }
1204 } 1220 }
1205 SkImageInfo info = SkImageInfo::MakeN32(ir.width(), ir.height(),
1206 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
1207 1221
1208 SkBaseDevice* device = this->getTopDevice(); 1222 SkBaseDevice* device = this->getTopDevice();
1209 if (nullptr == device) { 1223 if (nullptr == device) {
1210 SkDebugf("Unable to find device for layer."); 1224 SkDebugf("Unable to find device for layer.");
1211 return; 1225 return;
1212 } 1226 }
1213 1227
1228 SkImageInfo info = make_layer_info(device->imageInfo(), ir.width(), ir.heigh t(), isOpaque,
1229 paint);
1230
1214 bool forceSpriteOnRestore = false; 1231 bool forceSpriteOnRestore = false;
1215 { 1232 {
1216 const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() || 1233 const bool preserveLCDText = kOpaque_SkAlphaType == info.alphaType() ||
1217 (saveLayerFlags & kPreserveLCDText_SaveLaye rFlag); 1234 (saveLayerFlags & kPreserveLCDText_SaveLaye rFlag);
1218 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage; 1235 const SkBaseDevice::TileUsage usage = SkBaseDevice::kNever_TileUsage;
1219 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo, 1236 const SkBaseDevice::CreateInfo createInfo = SkBaseDevice::CreateInfo(inf o, usage, geo,
1220 pres erveLCDText, false); 1237 pres erveLCDText, false);
1221 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint); 1238 SkBaseDevice* newDev = device->onCreateDevice(createInfo, paint);
1222 if (nullptr == newDev) { 1239 if (nullptr == newDev) {
1223 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint) 1240 // If onCreateDevice didn't succeed, try raster (e.g. PDF couldn't h andle the paint)
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 if (this->quickReject(tmp)) { 2210 if (this->quickReject(tmp)) {
2194 return; 2211 return;
2195 } 2212 }
2196 } 2213 }
2197 2214
2198 SkLazyPaint lazy; 2215 SkLazyPaint lazy;
2199 if (nullptr == paint) { 2216 if (nullptr == paint) {
2200 paint = lazy.init(); 2217 paint = lazy.init();
2201 } 2218 }
2202 2219
2203 const bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image->height(), 2220 bool drawAsSprite = this->canDrawBitmapAsSprite(x, y, image->width(), image- >height(),
2204 *paint); 2221 *paint);
2222 if (drawAsSprite && paint->getImageFilter()) {
2223 SkBitmap bitmap;
2224 if (!as_IB(image)->asBitmapForImageFilters(&bitmap)) {
2225 drawAsSprite = false;
2226 } else{
2227 // Until imagefilters are updated, they cannot handle any src type b ut N32...
2228 if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().i sSRGB()) {
2229 drawAsSprite = false;
2230 }
2231 }
2232 }
2233
2205 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds) 2234 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, &bounds)
2206 2235
2207 while (iter.next()) { 2236 while (iter.next()) {
2208 const SkPaint& pnt = looper.paint(); 2237 const SkPaint& pnt = looper.paint();
2209 if (drawAsSprite && pnt.getImageFilter()) { 2238 if (drawAsSprite && pnt.getImageFilter()) {
2210 SkBitmap bitmap; 2239 SkBitmap bitmap;
2211 if (as_IB(image)->asBitmapForImageFilters(&bitmap)) { 2240 if (as_IB(image)->asBitmapForImageFilters(&bitmap)) {
2212 SkPoint pt; 2241 SkPoint pt;
2213 iter.fMatrix->mapXY(x, y, &pt); 2242 iter.fMatrix->mapXY(x, y, &pt);
2214 iter.fDevice->drawBitmapAsSprite(iter, bitmap, 2243 iter.fDevice->drawBitmapAsSprite(iter, bitmap,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2270 if (paint->canComputeFastBounds()) { 2299 if (paint->canComputeFastBounds()) {
2271 bitmap.getBounds(&storage); 2300 bitmap.getBounds(&storage);
2272 matrix.mapRect(&storage); 2301 matrix.mapRect(&storage);
2273 SkRect tmp = storage; 2302 SkRect tmp = storage;
2274 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) { 2303 if (this->quickReject(paint->computeFastBounds(tmp, &tmp))) {
2275 return; 2304 return;
2276 } 2305 }
2277 bounds = &storage; 2306 bounds = &storage;
2278 } 2307 }
2279 2308
2280 const bool drawAsSprite = bounds && this->canDrawBitmapAsSprite(x, y, bitmap .width(), 2309 bool drawAsSprite = bounds && this->canDrawBitmapAsSprite(x, y, bitmap.width (), bitmap.height(),
2281 bitmap.heigh t(), *paint); 2310 *paint);
2311 if (drawAsSprite && paint->getImageFilter()) {
2312 // Until imagefilters are updated, they cannot handle any src type but N 32...
2313 if (bitmap.info().colorType() != kN32_SkColorType || bitmap.info().isSRG B()) {
2314 drawAsSprite = false;
2315 }
2316 }
2317
2282 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds) 2318 LOOPER_BEGIN_DRAWBITMAP(*paint, drawAsSprite, bounds)
2283 2319
2284 while (iter.next()) { 2320 while (iter.next()) {
2285 const SkPaint& pnt = looper.paint(); 2321 const SkPaint& pnt = looper.paint();
2286 if (drawAsSprite && pnt.getImageFilter()) { 2322 if (drawAsSprite && pnt.getImageFilter()) {
2287 SkPoint pt; 2323 SkPoint pt;
2288 iter.fMatrix->mapXY(x, y, &pt); 2324 iter.fMatrix->mapXY(x, y, &pt);
2289 iter.fDevice->drawBitmapAsSprite(iter, bitmap, 2325 iter.fDevice->drawBitmapAsSprite(iter, bitmap,
2290 SkScalarRoundToInt(pt.fX), 2326 SkScalarRoundToInt(pt.fX),
2291 SkScalarRoundToInt(pt.fY), pnt); 2327 SkScalarRoundToInt(pt.fY), pnt);
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
2964 } 3000 }
2965 3001
2966 if (matrix) { 3002 if (matrix) {
2967 canvas->concat(*matrix); 3003 canvas->concat(*matrix);
2968 } 3004 }
2969 } 3005 }
2970 3006
2971 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { 3007 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() {
2972 fCanvas->restoreToCount(fSaveCount); 3008 fCanvas->restoreToCount(fSaveCount);
2973 } 3009 }
OLDNEW
« no previous file with comments | « src/core/SkBlitter_Sprite.cpp ('k') | src/core/SkSpanProcs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698