aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/GrReorderCommandBuilder.cpp
diff options
context:
space:
mode:
authorGravatar joshualitt <joshualitt@chromium.org>2015-05-07 11:14:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-07 11:14:30 -0700
commit3b58d75170508567436cce259384d336949407d4 (patch)
treeb2515a29a6a907033f0aefcc4f42a9ea34303323 /src/gpu/GrReorderCommandBuilder.cpp
parentfc00a7c5015ea534b0f28f8115bfb6253d275e1e (diff)
Initial CL to create Reorder command builder behind a flag
Diffstat (limited to 'src/gpu/GrReorderCommandBuilder.cpp')
-rw-r--r--src/gpu/GrReorderCommandBuilder.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/gpu/GrReorderCommandBuilder.cpp b/src/gpu/GrReorderCommandBuilder.cpp
new file mode 100644
index 0000000000..3ba95d7c96
--- /dev/null
+++ b/src/gpu/GrReorderCommandBuilder.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrReorderCommandBuilder.h"
+
+static bool intersect(const SkRect& a, const SkRect& b) {
+ SkASSERT(a.fLeft <= a.fRight && a.fTop <= a.fBottom &&
+ b.fLeft <= b.fRight && b.fTop <= b.fBottom);
+ return a.fLeft < b.fRight && b.fLeft < a.fRight &&
+ a.fTop < b.fBottom && b.fTop < a.fBottom;
+}
+
+GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, GrBatch* batch) {
+ // Check if there is a Batch Draw we can batch with by linearly searching back until we either
+ // 1) check every draw
+ // 2) intersect with something
+ // 3) find a 'blocker'
+ if (!this->cmdBuffer()->empty()) {
+ GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer());
+
+ do {
+ if (Cmd::kDrawBatch_CmdType == reverseIter->type()) {
+ DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get());
+
+ if (previous->fState->getPipeline()->isEqual(*state->getPipeline()) &&
+ previous->fBatch->combineIfPossible(batch)) {
+ return NULL;
+ }
+
+ if (intersect(previous->fBatch->bounds(), batch->bounds())) {
+ break;
+ }
+ } else {
+ // TODO temporary until we can navigate the other types of commands
+ break;
+ }
+ } while (reverseIter.previous());
+ }
+
+ return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch,
+ this->batchTarget()));
+}