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 19 matching lines...) Expand all Loading... |
30 #include "SkSmallAllocator.h" | 30 #include "SkSmallAllocator.h" |
31 #include "SkSurface_Base.h" | 31 #include "SkSurface_Base.h" |
32 #include "SkTextBlob.h" | 32 #include "SkTextBlob.h" |
33 #include "SkTextFormatParams.h" | 33 #include "SkTextFormatParams.h" |
34 #include "SkTLazy.h" | 34 #include "SkTLazy.h" |
35 #include "SkTraceEvent.h" | 35 #include "SkTraceEvent.h" |
36 | 36 |
37 #include <new> | 37 #include <new> |
38 | 38 |
39 #if SK_SUPPORT_GPU | 39 #if SK_SUPPORT_GPU |
| 40 #include "GrContext.h" |
40 #include "GrRenderTarget.h" | 41 #include "GrRenderTarget.h" |
| 42 #include "SkGr.h" |
41 #endif | 43 #endif |
42 | 44 |
43 /* | 45 /* |
44 * Return true if the drawing this rect would hit every pixels in the canvas. | 46 * Return true if the drawing this rect would hit every pixels in the canvas. |
45 * | 47 * |
46 * Returns false if | 48 * Returns false if |
47 * - rect does not contain the canvas' bounds | 49 * - rect does not contain the canvas' bounds |
48 * - paint is not fill | 50 * - paint is not fill |
49 * - paint would blur or otherwise change the coverage of the rect | 51 * - paint would blur or otherwise change the coverage of the rect |
50 */ | 52 */ |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 fSaveCount += 1; | 1140 fSaveCount += 1; |
1139 this->internalSaveLayer(bounds, paint, flags, strategy); | 1141 this->internalSaveLayer(bounds, paint, flags, strategy); |
1140 return this->getSaveCount() - 1; | 1142 return this->getSaveCount() - 1; |
1141 } | 1143 } |
1142 | 1144 |
1143 int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPai
nt* paint) { | 1145 int SkCanvas::saveLayerPreserveLCDTextRequests(const SkRect* bounds, const SkPai
nt* paint) { |
1144 unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag
; | 1146 unsigned flags = kARGB_ClipLayer_SaveFlag | kPreserveLCDText_PrivateSaveFlag
; |
1145 return this->saveLayer(bounds, paint, (SaveFlags)flags); | 1147 return this->saveLayer(bounds, paint, (SaveFlags)flags); |
1146 } | 1148 } |
1147 | 1149 |
| 1150 static void draw_filter_into_device(SkBaseDevice* src, SkImageFilter* filter, Sk
BaseDevice* dst) { |
| 1151 |
| 1152 SkBitmap srcBM; |
| 1153 |
| 1154 #if SK_SUPPORT_GPU |
| 1155 GrRenderTarget* srcRT = src->accessRenderTarget(); |
| 1156 if (srcRT && !srcRT->asTexture() && dst->accessRenderTarget()) { |
| 1157 // When both the src & the dst are on the gpu but the src doesn't have a
texture, |
| 1158 // we create a temporary texture for the draw. |
| 1159 // TODO: we should actually only copy the portion of the source needed t
o apply the image |
| 1160 // filter |
| 1161 GrContext* context = srcRT->getContext(); |
| 1162 SkAutoTUnref<GrTexture> tex(context->textureProvider()->createTexture(sr
cRT->desc(), true)); |
| 1163 |
| 1164 context->copySurface(tex, srcRT); |
| 1165 |
| 1166 GrWrapTextureInBitmap(tex, src->width(), src->height(), src->isOpaque(),
&srcBM); |
| 1167 } else |
| 1168 #endif |
| 1169 { |
| 1170 srcBM = src->accessBitmap(false); |
| 1171 } |
| 1172 |
| 1173 SkCanvas c(dst); |
| 1174 |
| 1175 SkPaint p; |
| 1176 p.setImageFilter(filter); |
| 1177 c.drawBitmap(srcBM, 0, 0, &p); |
| 1178 } |
1148 | 1179 |
1149 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, | 1180 void SkCanvas::internalSaveLayer(const SkRect* bounds, const SkPaint* paint, Sav
eFlags flags, |
1150 SaveLayerStrategy strategy) { | 1181 SaveLayerStrategy strategy) { |
1151 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG | 1182 #ifndef SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG |
1152 flags |= kClipToLayer_SaveFlag; | 1183 flags |= kClipToLayer_SaveFlag; |
1153 #endif | 1184 #endif |
1154 | 1185 |
1155 // do this before we create the layer. We don't call the public save() since | 1186 // do this before we create the layer. We don't call the public save() since |
1156 // that would invoke a possibly overridden virtual | 1187 // that would invoke a possibly overridden virtual |
1157 this->internalSave(); | 1188 this->internalSave(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 SkErrorInternals::SetError(kInternalError_SkError, | 1234 SkErrorInternals::SetError(kInternalError_SkError, |
1204 "Unable to create device for layer.")
; | 1235 "Unable to create device for layer.")
; |
1205 return; | 1236 return; |
1206 } | 1237 } |
1207 forceSpriteOnRestore = true; | 1238 forceSpriteOnRestore = true; |
1208 } | 1239 } |
1209 device = newDev; | 1240 device = newDev; |
1210 } | 1241 } |
1211 | 1242 |
1212 device->setOrigin(ir.fLeft, ir.fTop); | 1243 device->setOrigin(ir.fLeft, ir.fTop); |
| 1244 |
| 1245 if (0) { |
| 1246 draw_filter_into_device(fMCRec->fTopLayer->fDevice, nullptr, device); |
| 1247 } |
| 1248 |
1213 DeviceCM* layer = | 1249 DeviceCM* layer = |
1214 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri
teOnRestore); | 1250 new DeviceCM(device, paint, this, fConservativeRasterClip, forceSpri
teOnRestore); |
1215 device->unref(); | 1251 device->unref(); |
1216 | 1252 |
1217 layer->fNext = fMCRec->fTopLayer; | 1253 layer->fNext = fMCRec->fTopLayer; |
1218 fMCRec->fLayer = layer; | 1254 fMCRec->fLayer = layer; |
1219 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer | 1255 fMCRec->fTopLayer = layer; // this field is NOT an owner of layer |
1220 } | 1256 } |
1221 | 1257 |
1222 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { | 1258 int SkCanvas::saveLayerAlpha(const SkRect* bounds, U8CPU alpha) { |
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3013 } | 3049 } |
3014 | 3050 |
3015 if (matrix) { | 3051 if (matrix) { |
3016 canvas->concat(*matrix); | 3052 canvas->concat(*matrix); |
3017 } | 3053 } |
3018 } | 3054 } |
3019 | 3055 |
3020 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { | 3056 SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
3021 fCanvas->restoreToCount(fSaveCount); | 3057 fCanvas->restoreToCount(fSaveCount); |
3022 } | 3058 } |
OLD | NEW |