| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrReorderCommandBuilder.h" | 8 #include "GrReorderCommandBuilder.h" |
| 9 #include "SkStringUtils.h" |
| 9 | 10 |
| 10 template <class Left, class Right> | 11 template <class Left, class Right> |
| 11 static bool intersect(const Left& a, const Right& b) { | 12 static bool intersect(const Left& a, const Right& b) { |
| 12 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | 13 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
| 13 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | 14 b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 14 return a.fLeft < b.fRight && b.fLeft < a.fRight && | 15 return a.fLeft < b.fRight && b.fLeft < a.fRight && |
| 15 a.fTop < b.fBottom && b.fTop < a.fBottom; | 16 a.fTop < b.fBottom && b.fTop < a.fBottom; |
| 16 } | 17 } |
| 17 | 18 |
| 18 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrDrawBatch* bat
ch, | 19 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrBatch* batch, |
| 19 const GrCaps& ca
ps) { | 20 const GrCaps& ca
ps) { |
| 20 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | 21 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either |
| 21 // 1) check every draw | 22 // 1) check every draw |
| 22 // 2) intersect with something | 23 // 2) intersect with something |
| 23 // 3) find a 'blocker' | 24 // 3) find a 'blocker' |
| 24 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. | 25 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. |
| 25 static const int kMaxLookback = 10; | 26 static const int kMaxLookback = 10; |
| 26 int i = 0; | 27 int i = 0; |
| 27 | 28 |
| 28 GrRenderTarget* rt = batch->pipeline()->getRenderTarget(); | |
| 29 | |
| 30 GrBATCH_INFO("Re-Recording (%s, B%u)\n" | 29 GrBATCH_INFO("Re-Recording (%s, B%u)\n" |
| 31 "\tRenderTarget %p\n" | |
| 32 "\tBounds (%f, %f, %f, %f)\n", | 30 "\tBounds (%f, %f, %f, %f)\n", |
| 33 batch->name(), | 31 batch->name(), |
| 34 batch->uniqueID(), rt, | 32 batch->uniqueID(), |
| 35 batch->bounds().fLeft, batch->bounds().fRight, | 33 batch->bounds().fLeft, batch->bounds().fRight, |
| 36 batch->bounds().fTop, batch->bounds().fBottom); | 34 batch->bounds().fTop, batch->bounds().fBottom); |
| 37 if (GR_BATCH_SPEW) { | 35 GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); |
| 38 SkDebugf("\tColorStages:\n"); | |
| 39 for (int i = 0; i < batch->pipeline()->numColorFragmentStages(); i++) { | |
| 40 SkDebugf("\t\t%s\n", batch->pipeline()->getColorStage(i).processor()
->name()); | |
| 41 } | |
| 42 SkDebugf("\tCoverageStages:\n"); | |
| 43 for (int i = 0; i < batch->pipeline()->numCoverageFragmentStages(); i++)
{ | |
| 44 SkDebugf("\t\t%s\n", batch->pipeline()->getCoverageStage(i).processo
r()->name()); | |
| 45 } | |
| 46 SkDebugf("\tXP: %s\n", batch->pipeline()->getXferProcessor()->name()); | |
| 47 } | |
| 48 GrBATCH_INFO("\tOutcome:\n"); | 36 GrBATCH_INFO("\tOutcome:\n"); |
| 49 if (!this->cmdBuffer()->empty()) { | 37 if (!this->cmdBuffer()->empty()) { |
| 50 GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer())
; | 38 GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer())
; |
| 51 | 39 |
| 52 do { | 40 do { |
| 53 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { | 41 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { |
| 54 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; | 42 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; |
| 55 | 43 |
| 56 if (previous->batch()->pipeline()->getRenderTarget() != rt) { | 44 if (previous->batch()->renderTargetUniqueID() != batch->renderTa
rgetUniqueID()) { |
| 57 GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget
\n", | 45 GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget
\n", |
| 58 previous->batch()->name(), previous->batch()->u
niqueID()); | 46 previous->batch()->name(), previous->batch()->u
niqueID()); |
| 59 break; | 47 break; |
| 60 } | 48 } |
| 61 // We cannot continue to search backwards if the render target c
hanges | 49 // We cannot continue to search backwards if the render target c
hanges |
| 62 if (previous->batch()->combineIfPossible(batch, caps)) { | 50 if (previous->batch()->combineIfPossible(batch, caps)) { |
| 63 GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", | 51 GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", |
| 64 previous->batch()->name(), previous->batch()->u
niqueID()); | 52 previous->batch()->name(), previous->batch()->u
niqueID()); |
| 65 return NULL; | 53 return NULL; |
| 66 } | 54 } |
| 67 | 55 |
| 68 if (intersect(previous->batch()->bounds(), batch->bounds())) { | 56 if (intersect(previous->batch()->bounds(), batch->bounds())) { |
| 69 GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", | 57 GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", |
| 70 previous->batch()->name(), previous->batch()->u
niqueID()); | 58 previous->batch()->name(), previous->batch()->u
niqueID()); |
| 71 break; | 59 break; |
| 72 } | 60 } |
| 73 } else if (Cmd::kClear_CmdType == reverseIter->type()) { | |
| 74 Clear* previous = static_cast<Clear*>(reverseIter.get()); | |
| 75 | |
| 76 // We cannot continue to search backwards if the render target c
hanges | |
| 77 if (previous->renderTarget() != rt) { | |
| 78 GrBATCH_INFO("\t\tBreaking because of Clear's Rendertarget c
hange\n"); | |
| 79 break; | |
| 80 } | |
| 81 | |
| 82 // We set the color to illegal if we are doing a discard. | |
| 83 if (previous->fColor == GrColor_ILLEGAL || | |
| 84 intersect(batch->bounds(), previous->fRect)) { | |
| 85 GrBATCH_INFO("\t\tBreaking because of Clear intersection\n")
; | |
| 86 break; | |
| 87 } | |
| 88 } else { | 61 } else { |
| 89 GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter
->type()); | 62 GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter
->type()); |
| 90 // TODO temporary until we can navigate the other types of comma
nds | 63 // TODO temporary until we only have batches. |
| 91 break; | 64 break; |
| 92 } | 65 } |
| 93 } while (reverseIter.previous() && ++i < kMaxLookback); | 66 } while (reverseIter.previous() && ++i < kMaxLookback); |
| 94 #if GR_BATCH_SPEW | 67 #if GR_BATCH_SPEW |
| 95 if (!reverseIter.get()) { | 68 if (!reverseIter.get()) { |
| 96 GrBATCH_INFO("\t\tNo more commands to try and batch with\n"); | 69 GrBATCH_INFO("\t\tNo more commands to try and batch with\n"); |
| 97 } else if (i >= kMaxLookback) { | 70 } else if (i >= kMaxLookback) { |
| 98 GrBATCH_INFO("\t\tReached max lookback %d\n", i); | 71 GrBATCH_INFO("\t\tReached max lookback %d\n", i); |
| 99 } | 72 } |
| 100 #endif | 73 #endif |
| 101 } | 74 } |
| 102 #if GR_BATCH_SPEW | 75 #if GR_BATCH_SPEW |
| 103 else { | 76 else { |
| 104 GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); | 77 GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); |
| 105 } | 78 } |
| 106 #endif | 79 #endif |
| 107 | 80 |
| 108 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch)); | 81 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch)); |
| 109 } | 82 } |
| OLD | NEW |