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(GrBatch* batch)
{ | 18 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrBatch* batch, |
| 19 const GrCaps& ca
ps) { |
19 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | 20 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either |
20 // 1) check every draw | 21 // 1) check every draw |
21 // 2) intersect with something | 22 // 2) intersect with something |
22 // 3) find a 'blocker' | 23 // 3) find a 'blocker' |
23 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. | 24 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. |
24 static const int kMaxLookback = 10; | 25 static const int kMaxLookback = 10; |
25 int i = 0; | 26 int i = 0; |
26 | 27 |
27 GrRenderTarget* rt = batch->pipeline()->getRenderTarget(); | 28 GrRenderTarget* rt = batch->pipeline()->getRenderTarget(); |
28 | 29 |
(...skipping 22 matching lines...) Expand all Loading... |
51 do { | 52 do { |
52 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { | 53 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { |
53 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; | 54 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; |
54 | 55 |
55 if (previous->batch()->pipeline()->getRenderTarget() != rt) { | 56 if (previous->batch()->pipeline()->getRenderTarget() != rt) { |
56 GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget
\n", | 57 GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget
\n", |
57 previous->fBatch->name(), previous->fBatch->uni
queID()); | 58 previous->fBatch->name(), previous->fBatch->uni
queID()); |
58 break; | 59 break; |
59 } | 60 } |
60 // We cannot continue to search backwards if the render target c
hanges | 61 // We cannot continue to search backwards if the render target c
hanges |
61 if (previous->batch()->combineIfPossible(batch)) { | 62 if (previous->batch()->combineIfPossible(batch, caps)) { |
62 GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", | 63 GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", |
63 previous->fBatch->name(), previous->fBatch->uni
queID()); | 64 previous->fBatch->name(), previous->fBatch->uni
queID()); |
64 return NULL; | 65 return NULL; |
65 } | 66 } |
66 | 67 |
67 if (intersect(previous->batch()->bounds(), batch->bounds())) { | 68 if (intersect(previous->batch()->bounds(), batch->bounds())) { |
68 GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", | 69 GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", |
69 previous->fBatch->name(), previous->fBatch->uni
queID()); | 70 previous->fBatch->name(), previous->fBatch->uni
queID()); |
70 break; | 71 break; |
71 } | 72 } |
(...skipping 27 matching lines...) Expand all Loading... |
99 #endif | 100 #endif |
100 } | 101 } |
101 #if GR_BATCH_SPEW | 102 #if GR_BATCH_SPEW |
102 else { | 103 else { |
103 GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); | 104 GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); |
104 } | 105 } |
105 #endif | 106 #endif |
106 | 107 |
107 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch, this-
>batchTarget())); | 108 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch, this-
>batchTarget())); |
108 } | 109 } |
OLD | NEW |