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