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 1128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 SaveLayerRec rec(origRec); | 1139 SaveLayerRec rec(origRec); |
1140 if (gIgnoreSaveLayerBounds) { | 1140 if (gIgnoreSaveLayerBounds) { |
1141 rec.fBounds = nullptr; | 1141 rec.fBounds = nullptr; |
1142 } | 1142 } |
1143 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); | 1143 SaveLayerStrategy strategy = this->getSaveLayerStrategy(rec); |
1144 fSaveCount += 1; | 1144 fSaveCount += 1; |
1145 this->internalSaveLayer(rec, strategy); | 1145 this->internalSaveLayer(rec, strategy); |
1146 return this->getSaveCount() - 1; | 1146 return this->getSaveCount() - 1; |
1147 } | 1147 } |
1148 | 1148 |
1149 static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt
er, | 1149 void SkCanvas::DrawDeviceWithFilter(SkBaseDevice* src, const SkImageFilter* filt
er, |
1150 SkBaseDevice* dst, const SkMatrix& ctm) { | 1150 SkBaseDevice* dst, const SkMatrix& ctm, |
1151 | 1151 const SkClipStack* clipStack) { |
1152 SkBitmap srcBM; | 1152 SkDraw draw; |
1153 | 1153 SkRasterClip rc; |
1154 #if SK_SUPPORT_GPU | 1154 rc.setRect(SkIRect::MakeWH(dst->width(), dst->height())); |
1155 // TODO: remove this virtual usage of accessRenderTarget! It is preventing | 1155 draw.fMatrix = &SkMatrix::I(); |
1156 // removal of the virtual on SkBaseDevice. | 1156 draw.fRC = &rc; |
1157 GrRenderTarget* srcRT = src->accessRenderTarget(); | 1157 draw.fClipStack = clipStack; |
1158 if (srcRT && !srcRT->asTexture() && dst->accessRenderTarget()) { | 1158 draw.fDevice = dst; |
1159 // When both the src & the dst are on the gpu but the src doesn't have a
texture, | |
1160 // we create a temporary texture for the draw. | |
1161 // TODO: we should actually only copy the portion of the source needed t
o apply the image | |
1162 // filter | |
1163 GrContext* context = srcRT->getContext(); | |
1164 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(sr
cRT->desc(), | |
1165 Sk
Budgeted::kYes)); | |
1166 | |
1167 context->copySurface(tex, srcRT); | |
1168 | |
1169 GrWrapTextureInBitmap(tex, src->width(), src->height(), src->isOpaque(),
&srcBM); | |
1170 } else | |
1171 #endif | |
1172 { | |
1173 srcBM = src->accessBitmap(false); | |
1174 } | |
1175 | |
1176 SkCanvas c(dst); | |
1177 | 1159 |
1178 SkPaint p; | 1160 SkPaint p; |
1179 p.setImageFilter(filter->makeWithLocalMatrix(ctm)); | 1161 p.setImageFilter(filter->makeWithLocalMatrix(ctm)); |
1180 const SkScalar x = SkIntToScalar(src->getOrigin().x()); | 1162 |
1181 const SkScalar y = SkIntToScalar(src->getOrigin().y()); | 1163 dst->drawDevice(draw, src, |
1182 c.drawBitmap(srcBM, x, y, &p); | 1164 src->getOrigin().x() - dst->getOrigin().x(), |
| 1165 src->getOrigin().y() - dst->getOrigin().y(), |
| 1166 p); |
1183 } | 1167 } |
1184 | 1168 |
1185 static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i
sOpaque, | 1169 static SkImageInfo make_layer_info(const SkImageInfo& prev, int w, int h, bool i
sOpaque, |
1186 const SkPaint* paint) { | 1170 const SkPaint* paint) { |
1187 // need to force L32 for now if we have an image filter. Once filters suppor
t other colortypes | 1171 // need to force L32 for now if we have an image filter. Once filters suppor
t other colortypes |
1188 // e.g. sRGB or F16, we can remove this check | 1172 // e.g. sRGB or F16, we can remove this check |
1189 // SRGBTODO: Can we remove this check now? | 1173 // SRGBTODO: Can we remove this check now? |
1190 const bool hasImageFilter = paint && paint->getImageFilter(); | 1174 const bool hasImageFilter = paint && paint->getImageFilter(); |
1191 | 1175 |
1192 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType
; | 1176 SkAlphaType alphaType = isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType
; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 pre
serveLCDText); | 1271 pre
serveLCDText); |
1288 newDevice.reset(priorDevice->onCreateDevice(createInfo, paint)); | 1272 newDevice.reset(priorDevice->onCreateDevice(createInfo, paint)); |
1289 if (!newDevice) { | 1273 if (!newDevice) { |
1290 SkErrorInternals::SetError(kInternalError_SkError, | 1274 SkErrorInternals::SetError(kInternalError_SkError, |
1291 "Unable to create device for layer."); | 1275 "Unable to create device for layer."); |
1292 return; | 1276 return; |
1293 } | 1277 } |
1294 } | 1278 } |
1295 newDevice->setOrigin(ir.fLeft, ir.fTop); | 1279 newDevice->setOrigin(ir.fLeft, ir.fTop); |
1296 | 1280 |
1297 if (rec.fBackdrop) { | |
1298 draw_filter_into_device(priorDevice, rec.fBackdrop, newDevice, fMCRec->f
Matrix); | |
1299 } | |
1300 | |
1301 DeviceCM* layer = new DeviceCM(newDevice, paint, this, fConservativeRasterCl
ip, stashedMatrix); | 1281 DeviceCM* layer = new DeviceCM(newDevice, paint, this, fConservativeRasterCl
ip, stashedMatrix); |
1302 | 1282 |
1303 layer->fNext = fMCRec->fTopLayer; | 1283 layer->fNext = fMCRec->fTopLayer; |
1304 fMCRec->fLayer = layer; | 1284 fMCRec->fLayer = layer; |
1305 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 1285 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
| 1286 |
| 1287 if (rec.fBackdrop) { |
| 1288 DrawDeviceWithFilter(priorDevice, rec.fBackdrop, newDevice, |
| 1289 fMCRec->fMatrix, this->getClipStack()); |
| 1290 } |
1306 } | 1291 } |
1307 | 1292 |
1308 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 1293 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
1309 if (0xFF == alpha) { | 1294 if (0xFF == alpha) { |
1310 return this->saveLayer(bounds, nullptr); | 1295 return this->saveLayer(bounds, nullptr); |
1311 } else { | 1296 } else { |
1312 SkPaint tmpPaint; | 1297 SkPaint tmpPaint; |
1313 tmpPaint.setAlpha(alpha); | 1298 tmpPaint.setAlpha(alpha); |
1314 return this->saveLayer(bounds, &tmpPaint); | 1299 return this->saveLayer(bounds, &tmpPaint); |
1315 } | 1300 } |
(...skipping 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 | 3103 |
3119 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3104 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3120 fCanvas->restoreToCount(fSaveCount); | 3105 fCanvas->restoreToCount(fSaveCount); |
3121 } | 3106 } |
3122 | 3107 |
3123 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API | 3108 #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API |
3124 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { | 3109 SkSurface* SkCanvas::newSurface(const SkImageInfo& info, const SkSurfaceProps* p
rops) { |
3125 return this->makeSurface(info, props).release(); | 3110 return this->makeSurface(info, props).release(); |
3126 } | 3111 } |
3127 #endif | 3112 #endif |
OLD | NEW |