| 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 #if SK_SUPPORT_GPU | 8 #if SK_SUPPORT_GPU |
| 9 #include "GrLayerHoister.h" | 9 #include "GrLayerHoister.h" |
| 10 #include "GrRecordReplaceDraw.h" | 10 #include "GrRecordReplaceDraw.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 fGPUDrawData.setReserve(reserve); | 51 fGPUDrawData.setReserve(reserve); |
| 52 fThreadSafeDrawData.setReserve(reserve); | 52 fThreadSafeDrawData.setReserve(reserve); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 void SkMultiPictureDraw::reset() { | 56 void SkMultiPictureDraw::reset() { |
| 57 DrawData::Reset(fGPUDrawData); | 57 DrawData::Reset(fGPUDrawData); |
| 58 DrawData::Reset(fThreadSafeDrawData); | 58 DrawData::Reset(fThreadSafeDrawData); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void SkMultiPictureDraw::add(SkCanvas* canvas, | 61 void SkMultiPictureDraw::add(SkCanvas* canvas, |
| 62 const SkPicture* picture, | 62 const SkPicture* picture, |
| 63 const SkMatrix* matrix, | 63 const SkMatrix* matrix, |
| 64 const SkPaint* paint) { | 64 const SkPaint* paint) { |
| 65 if (NULL == canvas || NULL == picture) { | 65 if (NULL == canvas || NULL == picture) { |
| 66 SkDEBUGFAIL("parameters to SkMultiPictureDraw::add should be non-NULL"); | 66 SkDEBUGFAIL("parameters to SkMultiPictureDraw::add should be non-NULL"); |
| 67 return; | 67 return; |
| 68 } | 68 } |
| 69 | 69 |
| 70 SkTDArray<DrawData>& array = canvas->getGrContext() ? fGPUDrawData : fThread
SafeDrawData; | 70 SkTDArray<DrawData>& array = canvas->getGrContext() ? fGPUDrawData : fThread
SafeDrawData; |
| 71 array.append()->init(canvas, picture, matrix, paint); | 71 array.append()->init(canvas, picture, matrix, paint); |
| 72 } | 72 } |
| 73 | 73 |
| 74 #undef SK_IGNORE_GPU_LAYER_HOISTING | 74 #undef SK_IGNORE_GPU_LAYER_HOISTING |
| 75 #define SK_IGNORE_GPU_LAYER_HOISTING 1 | 75 #define SK_IGNORE_GPU_LAYER_HOISTING 1 |
| 76 | 76 |
| 77 class AutoMPDReset : SkNoncopyable { | 77 class AutoMPDReset : SkNoncopyable { |
| 78 SkMultiPictureDraw* fMPD; | 78 SkMultiPictureDraw* fMPD; |
| 79 public: | 79 public: |
| 80 AutoMPDReset(SkMultiPictureDraw* mpd) : fMPD(mpd) {} | 80 AutoMPDReset(SkMultiPictureDraw* mpd) : fMPD(mpd) {} |
| 81 ~AutoMPDReset() { fMPD->reset(); } | 81 ~AutoMPDReset() { fMPD->reset(); } |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 void SkMultiPictureDraw::draw() { | 84 void SkMultiPictureDraw::draw() { |
| 85 AutoMPDReset mpdreset(this); | 85 AutoMPDReset mpdreset(this); |
| 86 // we place the taskgroup after the MPDReset, to ensure that we don't delete
the DrawData | 86 // we place the taskgroup after the MPDReset, to ensure that we don't delete
the DrawData |
| 87 // objects until after we're finished the tasks (which have pointers to the
data). | 87 // objects until after we're finished the tasks (which have pointers to the
data). |
| 88 | 88 |
| 89 SkTaskGroup group; | 89 SkTaskGroup group; |
| 90 for (int i = 0; i < fThreadSafeDrawData.count(); ++i) { | 90 for (int i = 0; i < fThreadSafeDrawData.count(); ++i) { |
| 91 group.add(DrawData::Run, &fThreadSafeDrawData[i]); | 91 group.add(DrawData::Draw, &fThreadSafeDrawData[i]); |
| 92 } | 92 } |
| 93 // we deliberately don't call wait() here, since the destructor will do that
, this allows us | 93 // we deliberately don't call wait() here, since the destructor will do that
, this allows us |
| 94 // to continue processing gpu-data without having to wait on the cpu tasks. | 94 // to continue processing gpu-data without having to wait on the cpu tasks. |
| 95 | 95 |
| 96 const int count = fGPUDrawData.count(); | 96 const int count = fGPUDrawData.count(); |
| 97 if (0 == count) { | 97 if (0 == count) { |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 | 100 |
| 101 #ifndef SK_IGNORE_GPU_LAYER_HOISTING | 101 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 SkRect clipBounds; | 120 SkRect clipBounds; |
| 121 if (!data.fCanvas->getClipBounds(&clipBounds)) { | 121 if (!data.fCanvas->getClipBounds(&clipBounds)) { |
| 122 continue; | 122 continue; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // TODO: sorting the cacheable layers from smallest to largest | 125 // TODO: sorting the cacheable layers from smallest to largest |
| 126 // would improve the packing and reduce the number of swaps | 126 // would improve the packing and reduce the number of swaps |
| 127 // TODO: another optimization would be to make a first pass to | 127 // TODO: another optimization would be to make a first pass to |
| 128 // lock any required layer that is already in the atlas | 128 // lock any required layer that is already in the atlas |
| 129 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, | 129 GrLayerHoister::FindLayersToAtlas(context, data.fPicture, |
| 130 clipBounds, | 130 clipBounds, |
| 131 &atlasedNeedRendering, &atlasedRec
ycled); | 131 &atlasedNeedRendering, &atlasedRec
ycled); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); | 135 GrLayerHoister::DrawLayersToAtlas(context, atlasedNeedRendering); |
| 136 | 136 |
| 137 SkTDArray<GrHoistedLayer> needRendering, recycled; | 137 SkTDArray<GrHoistedLayer> needRendering, recycled; |
| 138 #endif | 138 #endif |
| 139 | 139 |
| 140 for (int i = 0; i < count; ++i) { | 140 for (int i = 0; i < count; ++i) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); | 178 canvas->drawPicture(picture, &data.fMatrix, data.fPaint); |
| 179 } | 179 } |
| 180 } | 180 } |
| 181 | 181 |
| 182 #ifndef SK_IGNORE_GPU_LAYER_HOISTING | 182 #ifndef SK_IGNORE_GPU_LAYER_HOISTING |
| 183 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); | 183 GrLayerHoister::UnlockLayers(context, atlasedNeedRendering); |
| 184 GrLayerHoister::UnlockLayers(context, atlasedRecycled); | 184 GrLayerHoister::UnlockLayers(context, atlasedRecycled); |
| 185 #endif | 185 #endif |
| 186 } | 186 } |
| 187 | 187 |
| OLD | NEW |