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 "SkBitmapDevice.h" | 8 #include "SkBitmapDevice.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkCanvasPriv.h" | 10 #include "SkCanvasPriv.h" |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1141 SaveLayerRec rec(origRec); | 1141 SaveLayerRec rec(origRec); |
1142 if (gIgnoreSaveLayerBounds) { | 1142 if (gIgnoreSaveLayerBounds) { |
1143 rec.fBounds = nullptr; | 1143 rec.fBounds = nullptr; |
1144 } | 1144 } |
1145 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); | 1145 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); |
1146 fSaveCount += 1; | 1146 fSaveCount += 1; |
1147 this->internalSaveLayer(rec, strategy); | 1147 this->internalSaveLayer(rec, strategy); |
1148 return this->getSaveCount() - 1; | 1148 return this->getSaveCount() - 1; |
1149 } | 1149 } |
1150 | 1150 |
1151 static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt er, | 1151 void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filt er, |
1152 SkBaseDevice* dst, const SkMatrix& ctm) { | 1152 SkBaseDevice* dst, const SkMatrix& ctm, |
1153 | 1153 const SkClipStack* clipStack) { |
1154 SkBitmap srcBM; | 1154 SkDraw draw; |
1155 | 1155 SkRasterClip rc; |
1156 #if SK_SUPPORT_GPU | 1156 rc.setRect(SkIRect::MakeWH(dst->width(), dst->height())); |
1157 // TODO: remove this virtual usage of accessRenderTarget! It is preventing | 1157 draw.fMatrix = &SkMatrix::I(); |
1158 // removal of the virtual on SkBaseDevice. | 1158 draw.fRC = &rc; |
1159 GrRenderTarget* srcRT = src->accessRenderTarget(); | 1159 draw.fClipStack = clipStack; |
1160 if (srcRT && !srcRT->asTexture() && dst->accessRenderTarget()) { | 1160 draw.fDevice = dst; |
1161 // When both the src & the dst are on the gpu but the src doesn't have a texture, | |
1162 // we create a temporary texture for the draw. | |
1163 // TODO: we should actually only copy the portion of the source needed t o apply the image | |
1164 // filter | |
1165 GrContext* context = srcRT->getContext(); | |
1166 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(sr cRT->desc(), | |
1167 Sk Budgeted::kYes)); | |
1168 | |
1169 context->copySurface(tex, srcRT); | |
1170 | |
1171 GrWrapTextureInBitmap(tex, src->width(), src->height(), src->isOpaque(), &srcBM); | |
1172 } else | |
1173 #endif | |
1174 { | |
1175 srcBM = src->accessBitmap(false); | |
1176 } | |
1177 | |
1178 SkCanvas c(dst); | |
1179 | 1161 |
1180 SkPaint p; | 1162 SkPaint p; |
1181 p.setImageFilter(filter->makeWithLocalMatrix(ctm)); | 1163 p.setImageFilter(filter->makeWithLocalMatrix(ctm)); |
1182 const SkScalar x = SkIntToScalar(src->getOrigin().x()); | 1164 |
1183 const SkScalar y = SkIntToScalar(src->getOrigin().y()); | 1165 dst->drawDevice(draw, src, |
1184 c.drawBitmap(srcBM, x, y, &p); | 1166 src->getOrigin().x() - dst->getOrigin().x(), |
1167 src->getOrigin().y() - dst->getOrigin().y(), | |
1168 p); | |
1185 } | 1169 } |
1186 | 1170 |
1187 static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i sOpaque, | 1171 static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i sOpaque, |
1188 const SkPaint* paint) { | 1172 const SkPaint* paint) { |
1189 // need to force L32 for now if we have an image filter. Once filters suppor t other colortypes | 1173 // need to force L32 for now if we have an image filter. Once filters suppor t other colortypes |
1190 // e.g. sRGB or F16, we can remove this check | 1174 // e.g. sRGB or F16, we can remove this check |
1191 // SRGBTODO: Can we remove this check now? | 1175 // SRGBTODO: Can we remove this check now? |
1192 const bool hasImageFilter = paint && paint->getImageFilter(); | 1176 const bool hasImageFilter = paint && paint->getImageFilter(); |
1193 | 1177 |
1194 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType ; | 1178 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType ; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1296 SkErrorInternals::SetError(kInternalError_SkError, | 1280 SkErrorInternals::SetError(kInternalError_SkError, |
1297 "Unable to create device for layer.") ; | 1281 "Unable to create device for layer.") ; |
1298 return; | 1282 return; |
1299 } | 1283 } |
1300 forceSpriteOnRestore = true; | 1284 forceSpriteOnRestore = true; |
1301 } | 1285 } |
1302 device = newDev; | 1286 device = newDev; |
1303 } | 1287 } |
1304 device->setOrigin(ir.fLeft, ir.fTop); | 1288 device->setOrigin(ir.fLeft, ir.fTop); |
1305 | 1289 |
1290 DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip, | |
1291 forceSpriteOnRestore, stashedMatrix); | |
1292 | |
1306 if (rec.fBackdrop) { | 1293 if (rec.fBackdrop) { |
1307 draw_filter_into_device(fMCRec->fTopLayer->fDevice, rec.fBackdrop, devic e, fMCRec->fMatrix); | 1294 DrawDeviceWithFilter(this->getTopDevice(), rec.fBackdrop, device, |
1295 fMCRec->fMatrix, this->getClipStack()); | |
1308 } | 1296 } |
1309 | 1297 |
1310 DeviceCM* layer = new DeviceCM(device, paint, this, fConservativeRasterClip, | |
1311 forceSpriteOnRestore, stashedMatrix); | |
1312 device->unref(); | 1298 device->unref(); |
1313 | 1299 |
1314 layer->fNext = fMCRec->fTopLayer; | 1300 layer->fNext = fMCRec->fTopLayer; |
1315 fMCRec->fLayer = layer; | 1301 fMCRec->fLayer = layer; |
1316 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 1302 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
1317 } | 1303 } |
reed1
2016/07/15 16:00:56
Can we move the "seed-the-new-top-device-pixels" c
robertphillips
2016/07/18 16:39:40
Done.
| |
1318 | 1304 |
1319 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 1305 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
1320 if (0xFF == alpha) { | 1306 if (0xFF == alpha) { |
1321 return this->saveLayer(bounds, nullptr); | 1307 return this->saveLayer(bounds, nullptr); |
1322 } else { | 1308 } else { |
1323 SkPaint tmpPaint; | 1309 SkPaint tmpPaint; |
1324 tmpPaint.setAlpha(alpha); | 1310 tmpPaint.setAlpha(alpha); |
1325 return this->saveLayer(bounds, &tmpPaint); | 1311 return this->saveLayer(bounds, &tmpPaint); |
1326 } | 1312 } |
1327 } | 1313 } |
(...skipping 1806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3134 | 3120 |
3135 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3121 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3136 fCanvas->restoreToCount(fSaveCount); | 3122 fCanvas->restoreToCount(fSaveCount); |
3137 } | 3123 } |
3138 | 3124 |
3139 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3125 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3140 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { | 3126 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p rops) { |
3141 return this->makeSurface(info, props).release(); | 3127 return this->makeSurface(info, props).release(); |
3142 } | 3128 } |
3143 #endif | 3129 #endif |
OLD | NEW |