OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2015 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "GrReorderCommandBuilder.h" | |
9 #include "SkStringUtils.h" | |
10 | |
11 template <class Left, class Right> | |
12 static bool intersect(const Left& a, const Right& b) { | |
13 SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom && | |
14 b.fLeft <= b.fRight && b.fTop <= b.fBottom); | |
15 return a.fLeft < b.fRight && b.fLeft < a.fRight && | |
16 a.fTop < b.fBottom && b.fTop < a.fBottom; | |
17 } | |
18 | |
19 GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(GrBatch* batch, | |
20 const GrCaps& ca
ps) { | |
21 // Check if there is a Batch Draw we can batch with by linearly searching ba
ck until we either | |
22 // 1) check every draw | |
23 // 2) intersect with something | |
24 // 3) find a 'blocker' | |
25 // Experimentally we have found that most batching occurs within the first 1
0 comparisons. | |
26 static const int kMaxLookback = 10; | |
27 int i = 0; | |
28 | |
29 GrBATCH_INFO("Re-Recording (%s, B%u)\n" | |
30 "\tBounds (%f, %f, %f, %f)\n", | |
31 batch->name(), | |
32 batch->uniqueID(), | |
33 batch->bounds().fLeft, batch->bounds().fRight, | |
34 batch->bounds().fTop, batch->bounds().fBottom); | |
35 GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); | |
36 GrBATCH_INFO("\tOutcome:\n"); | |
37 if (!this->cmdBuffer()->empty()) { | |
38 GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer())
; | |
39 | |
40 do { | |
41 if (Cmd::kDrawBatch_CmdType == reverseIter->type()) { | |
42 DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get())
; | |
43 | |
44 if (previous->batch()->renderTargetUniqueID() != batch->renderTa
rgetUniqueID()) { | |
45 GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget
\n", | |
46 previous->batch()->name(), previous->batch()->u
niqueID()); | |
47 break; | |
48 } | |
49 // We cannot continue to search backwards if the render target c
hanges | |
50 if (previous->batch()->combineIfPossible(batch, caps)) { | |
51 GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", | |
52 previous->batch()->name(), previous->batch()->u
niqueID()); | |
53 return nullptr; | |
54 } | |
55 | |
56 if (intersect(previous->batch()->bounds(), batch->bounds())) { | |
57 GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n", | |
58 previous->batch()->name(), previous->batch()->u
niqueID()); | |
59 break; | |
60 } | |
61 } else { | |
62 GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter
->type()); | |
63 // TODO temporary until we only have batches. | |
64 break; | |
65 } | |
66 } while (reverseIter.previous() && ++i < kMaxLookback); | |
67 #if GR_BATCH_SPEW | |
68 if (!reverseIter.get()) { | |
69 GrBATCH_INFO("\t\tNo more commands to try and batch with\n"); | |
70 } else if (i >= kMaxLookback) { | |
71 GrBATCH_INFO("\t\tReached max lookback %d\n", i); | |
72 } | |
73 #endif | |
74 } | |
75 #if GR_BATCH_SPEW | |
76 else { | |
77 GrBATCH_INFO("\t\tBreaking because empty command buffer\n"); | |
78 } | |
79 #endif | |
80 | |
81 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch)); | |
82 } | |
OLD | NEW |