| 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 | 9 |
| 10 static bool intersect(const SkRect& a, const SkRect& b) { | 10 static bool intersect(const SkRect& a, const SkRect& b) { |
| 11 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | 11 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && |
| 12 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | 12 b.fLeft <= b.fRight && b.fTop <= b.fBottom); |
| 13 return a.fLeft < b.fRight && b.fLeft < a.fRight && | 13 return a.fLeft < b.fRight && b.fLeft < a.fRight && |
| 14 a.fTop < b.fBottom && b.fTop < a.fBottom; | 14 a.fTop < b.fBottom && b.fTop < a.fBottom; |
| 15 } | 15 } |
| 16 | 16 |
| 17 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr
Batch* batch) { | 17 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr
Batch* batch) { |
| 18 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | 18 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either |
| 19 // 1) check every draw | 19 // 1) check every draw |
| 20 // 2) intersect with something | 20 // 2) intersect with something |
| 21 // 3) find a 'blocker' | 21 // 3) find a 'blocker' |
| 22 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. |
| 23 static const int kMaxLookback = 10; |
| 24 int i = 0; |
| 22 if (!this->cmdBuffer()->empty()) { | 25 if (!this->cmdBuffer()->empty()) { |
| 23 GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer())
; | 26 GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer())
; |
| 24 | 27 |
| 25 do { | 28 do { |
| 26 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { | 29 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { |
| 27 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; | 30 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; |
| 28 | 31 |
| 29 if (previous->fState->getPipeline()->isEqual(*state->getPipeline
()) && | 32 if (previous->fState->getPipeline()->isEqual(*state->getPipeline
()) && |
| 30 previous->fBatch->combineIfPossible(batch)) { | 33 previous->fBatch->combineIfPossible(batch)) { |
| 31 return NULL; | 34 return NULL; |
| 32 } | 35 } |
| 33 | 36 |
| 34 if (intersect(previous->fBatch->bounds(), batch->bounds())) { | 37 if (intersect(previous->fBatch->bounds(), batch->bounds())) { |
| 35 break; | 38 break; |
| 36 } | 39 } |
| 37 } else { | 40 } else { |
| 38 // TODO temporary until we can navigate the other types of comma
nds | 41 // TODO temporary until we can navigate the other types of comma
nds |
| 39 break; | 42 break; |
| 40 } | 43 } |
| 41 } while (reverseIter.previous()); | 44 } while (reverseIter.previous() && ++i < kMaxLookback); |
| 42 } | 45 } |
| 43 | 46 |
| 44 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch
, | 47 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch
, |
| 45 this->batchT
arget())); | 48 this->batchT
arget())); |
| 46 } | 49 } |
| OLD | NEW |