| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 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 "GrPictureUtils.h" | 8 #include "GrPictureUtils.h" |
| 9 #include "SkDevice.h" | 9 #include "SkDevice.h" |
| 10 #include "SkDraw.h" |
| 11 #include "SkPaintPriv.h" |
| 10 | 12 |
| 11 // The GrGather device performs GPU-backend-specific preprocessing on | 13 // The GrGather device performs GPU-backend-specific preprocessing on |
| 12 // a picture. The results are stored in a GPUAccelData. | 14 // a picture. The results are stored in a GPUAccelData. |
| 13 // | 15 // |
| 14 // Currently the only interesting work is done in drawDevice (i.e., when a | 16 // Currently the only interesting work is done in drawDevice (i.e., when a |
| 15 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. | 17 // saveLayer is collapsed back into its parent) and, maybe, in onCreateDevice. |
| 16 // All the current work could be done much more efficiently by just traversing t
he | 18 // All the current work could be done much more efficiently by just traversing t
he |
| 17 // raw op codes in the SkPicture (although we would still need to replay all the | 19 // raw op codes in the SkPicture (although we would still need to replay all the |
| 18 // clip calls). | 20 // clip calls). |
| 19 class GrGatherDevice : public SkBaseDevice { | 21 class GrGatherDevice : public SkBaseDevice { |
| 20 public: | 22 public: |
| 21 SK_DECLARE_INST_COUNT(GrGatherDevice) | 23 SK_DECLARE_INST_COUNT(GrGatherDevice) |
| 22 | 24 |
| 23 GrGatherDevice(int width, int height, SkPicture* picture, GPUAccelData* acce
lData) { | 25 GrGatherDevice(int width, int height, SkPicture* picture, GPUAccelData* acce
lData, |
| 26 int saveLayerDepth) { |
| 24 fPicture = picture; | 27 fPicture = picture; |
| 28 fSaveLayerDepth = saveLayerDepth; |
| 29 fInfo.fValid = true; |
| 25 fInfo.fSize.set(width, height); | 30 fInfo.fSize.set(width, height); |
| 31 fInfo.fPaint = NULL; |
| 26 fInfo.fSaveLayerOpID = fPicture->EXPERIMENTAL_curOpID(); | 32 fInfo.fSaveLayerOpID = fPicture->EXPERIMENTAL_curOpID(); |
| 27 fInfo.fRestoreOpID = 0; | 33 fInfo.fRestoreOpID = 0; |
| 28 fInfo.fHasNestedLayers = false; | 34 fInfo.fHasNestedLayers = false; |
| 35 fInfo.fIsNested = (2 == fSaveLayerDepth); |
| 29 | 36 |
| 30 fEmptyBitmap.setConfig(SkImageInfo::Make(fInfo.fSize.fWidth, | 37 fEmptyBitmap.setConfig(SkImageInfo::Make(fInfo.fSize.fWidth, |
| 31 fInfo.fSize.fHeight, | 38 fInfo.fSize.fHeight, |
| 32 kUnknown_SkColorType, | 39 kUnknown_SkColorType, |
| 33 kIgnore_SkAlphaType)); | 40 kIgnore_SkAlphaType)); |
| 34 fAccelData = accelData; | 41 fAccelData = accelData; |
| 35 fAlreadyDrawn = false; | 42 fAlreadyDrawn = false; |
| 36 } | 43 } |
| 37 | 44 |
| 38 virtual ~GrGatherDevice() { } | 45 virtual ~GrGatherDevice() { } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 const SkPath& path, const SkMatrix* matrix, | 110 const SkPath& path, const SkMatrix* matrix, |
| 104 const SkPaint& paint) SK_OVERRIDE { | 111 const SkPaint& paint) SK_OVERRIDE { |
| 105 } | 112 } |
| 106 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, int vert
exCount, | 113 virtual void drawVertices(const SkDraw& draw, SkCanvas::VertexMode, int vert
exCount, |
| 107 const SkPoint verts[], const SkPoint texs[], | 114 const SkPoint verts[], const SkPoint texs[], |
| 108 const SkColor colors[], SkXfermode* xmode, | 115 const SkColor colors[], SkXfermode* xmode, |
| 109 const uint16_t indices[], int indexCount, | 116 const uint16_t indices[], int indexCount, |
| 110 const SkPaint& paint) SK_OVERRIDE { | 117 const SkPaint& paint) SK_OVERRIDE { |
| 111 } | 118 } |
| 112 virtual void drawDevice(const SkDraw& draw, SkBaseDevice* deviceIn, int x, i
nt y, | 119 virtual void drawDevice(const SkDraw& draw, SkBaseDevice* deviceIn, int x, i
nt y, |
| 113 const SkPaint&) SK_OVERRIDE { | 120 const SkPaint& paint) SK_OVERRIDE { |
| 121 // deviceIn is the one that is being "restored" back to its parent |
| 114 GrGatherDevice* device = static_cast<GrGatherDevice*>(deviceIn); | 122 GrGatherDevice* device = static_cast<GrGatherDevice*>(deviceIn); |
| 115 | 123 |
| 116 if (device->fAlreadyDrawn) { | 124 if (device->fAlreadyDrawn) { |
| 117 return; | 125 return; |
| 118 } | 126 } |
| 119 | 127 |
| 120 device->fInfo.fRestoreOpID = fPicture->EXPERIMENTAL_curOpID(); | 128 device->fInfo.fRestoreOpID = fPicture->EXPERIMENTAL_curOpID(); |
| 129 device->fInfo.fCTM = *draw.fMatrix; |
| 130 device->fInfo.fCTM.postTranslate(SkIntToScalar(-device->getOrigin().fX), |
| 131 SkIntToScalar(-device->getOrigin().fY))
; |
| 132 |
| 133 // We need the x & y values that will yield 'getOrigin' when transformed |
| 134 // by 'draw.fMatrix'. |
| 135 device->fInfo.fOffset.iset(device->getOrigin()); |
| 136 |
| 137 SkMatrix invMatrix; |
| 138 if (draw.fMatrix->invert(&invMatrix)) { |
| 139 invMatrix.mapPoints(&device->fInfo.fOffset, 1); |
| 140 } else { |
| 141 device->fInfo.fValid = false; |
| 142 } |
| 143 |
| 144 if (NeedsDeepCopy(paint)) { |
| 145 // This NULL acts as a signal that the paint was uncopyable (for now
) |
| 146 device->fInfo.fPaint = NULL; |
| 147 device->fInfo.fValid = false; |
| 148 } else { |
| 149 device->fInfo.fPaint = SkNEW_ARGS(SkPaint, (paint)); |
| 150 } |
| 151 |
| 121 fAccelData->addSaveLayerInfo(device->fInfo); | 152 fAccelData->addSaveLayerInfo(device->fInfo); |
| 122 device->fAlreadyDrawn = true; | 153 device->fAlreadyDrawn = true; |
| 123 } | 154 } |
| 124 // TODO: allow this call to return failure, or move to SkBitmapDevice only. | 155 // TODO: allow this call to return failure, or move to SkBitmapDevice only. |
| 125 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { | 156 virtual const SkBitmap& onAccessBitmap() SK_OVERRIDE { |
| 126 return fEmptyBitmap; | 157 return fEmptyBitmap; |
| 127 } | 158 } |
| 128 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG | 159 #ifdef SK_SUPPORT_LEGACY_READPIXELSCONFIG |
| 129 virtual bool onReadPixels(const SkBitmap& bitmap, | 160 virtual bool onReadPixels(const SkBitmap& bitmap, |
| 130 int x, int y, | 161 int x, int y, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 151 // All information gathered during the gather process is stored here | 182 // All information gathered during the gather process is stored here |
| 152 GPUAccelData* fAccelData; | 183 GPUAccelData* fAccelData; |
| 153 | 184 |
| 154 // true if this device has already been drawn back to its parent(s) at least | 185 // true if this device has already been drawn back to its parent(s) at least |
| 155 // once. | 186 // once. |
| 156 bool fAlreadyDrawn; | 187 bool fAlreadyDrawn; |
| 157 | 188 |
| 158 // The information regarding the saveLayer call this device represents. | 189 // The information regarding the saveLayer call this device represents. |
| 159 GPUAccelData::SaveLayerInfo fInfo; | 190 GPUAccelData::SaveLayerInfo fInfo; |
| 160 | 191 |
| 192 // The depth of this device in the saveLayer stack |
| 193 int fSaveLayerDepth; |
| 194 |
| 161 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI
DE { | 195 virtual void replaceBitmapBackendForRasterSurface(const SkBitmap&) SK_OVERRI
DE { |
| 162 NotSupported(); | 196 NotSupported(); |
| 163 } | 197 } |
| 164 | 198 |
| 165 virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) S
K_OVERRIDE { | 199 virtual SkBaseDevice* onCreateDevice(const SkImageInfo& info, Usage usage) S
K_OVERRIDE { |
| 166 // we expect to only get called via savelayer, in which case it is fine. | 200 // we expect to only get called via savelayer, in which case it is fine. |
| 167 SkASSERT(kSaveLayer_Usage == usage); | 201 SkASSERT(kSaveLayer_Usage == usage); |
| 168 | 202 |
| 169 fInfo.fHasNestedLayers = true; | 203 fInfo.fHasNestedLayers = true; |
| 170 return SkNEW_ARGS(GrGatherDevice, (info.width(), info.height(), fPicture
, fAccelData)); | 204 return SkNEW_ARGS(GrGatherDevice, (info.width(), info.height(), fPicture
, |
| 205 fAccelData, fSaveLayerDepth+1)); |
| 171 } | 206 } |
| 172 | 207 |
| 173 virtual void flush() SK_OVERRIDE {} | 208 virtual void flush() SK_OVERRIDE {} |
| 174 | 209 |
| 175 static void NotSupported() { | 210 static void NotSupported() { |
| 176 SkDEBUGFAIL("this method should never be called"); | 211 SkDEBUGFAIL("this method should never be called"); |
| 177 } | 212 } |
| 178 | 213 |
| 179 static void NothingToDo() {} | 214 static void NothingToDo() {} |
| 180 | 215 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 typedef SkCanvas INHERITED; | 267 typedef SkCanvas INHERITED; |
| 233 }; | 268 }; |
| 234 | 269 |
| 235 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's | 270 // GatherGPUInfo is only intended to be called within the context of SkGpuDevice
's |
| 236 // EXPERIMENTAL_optimize method. | 271 // EXPERIMENTAL_optimize method. |
| 237 void GatherGPUInfo(SkPicture* pict, GPUAccelData* accelData) { | 272 void GatherGPUInfo(SkPicture* pict, GPUAccelData* accelData) { |
| 238 if (0 == pict->width() || 0 == pict->height()) { | 273 if (0 == pict->width() || 0 == pict->height()) { |
| 239 return ; | 274 return ; |
| 240 } | 275 } |
| 241 | 276 |
| 242 GrGatherDevice device(pict->width(), pict->height(), pict, accelData); | 277 GrGatherDevice device(pict->width(), pict->height(), pict, accelData, 0); |
| 243 GrGatherCanvas canvas(&device, pict); | 278 GrGatherCanvas canvas(&device, pict); |
| 244 | 279 |
| 245 canvas.gather(); | 280 canvas.gather(); |
| 246 } | 281 } |
| OLD | NEW |