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