Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: src/gpu/GrBufferedDrawTarget.h

Issue 1225923010: Refugee from Dead Machine 4: MDB Monster Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Last update from dead machine Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/GrBlurUtils.cpp ('k') | src/gpu/GrBufferedDrawTarget.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrBufferedDrawTarget.h
diff --git a/src/gpu/GrBufferedDrawTarget.h b/src/gpu/GrBufferedDrawTarget.h
new file mode 100644
index 0000000000000000000000000000000000000000..7999b5d515109377355e94642a475aba9db9621b
--- /dev/null
+++ b/src/gpu/GrBufferedDrawTarget.h
@@ -0,0 +1,118 @@
+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrBufferedDrawTarget_DEFINED
+#define GrBufferedDrawTarget_DEFINED
+
+#include "GrDrawTarget.h"
+#include "GrCommandBuilder.h"
+#include "SkChunkAlloc.h"
+
+/**
+ * GrBufferedDrawTarget is an implementation of GrDrawTarget that queues up draws for eventual
+ * playback into a GrGpu. In theory one draw buffer could playback into another. Similarly, it is
+ * the caller's responsibility to ensure that all referenced textures, buffers, and render-targets
+ * are associated in the GrGpu object that the buffer is played back into.
+ */
+class GrBufferedDrawTarget : public GrClipTarget {
+public:
+
+ bool isEmpty() const override {
+ return fCommands->empty();
+ }
+
+ /**
+ * Creates a GrBufferedDrawTarget
+ *
+ * @param context the context object that owns this draw buffer.
+ */
+ GrBufferedDrawTarget(GrDrawContext* dc, GrRenderTarget* rt, GrContext* context);
+
+ ~GrBufferedDrawTarget() override;
+
+protected:
+ void appendIndicesAndTransforms(const void* indexValues, PathIndexType indexType,
+ const float* transformValues, PathTransformType transformType,
+ int count, char** indicesLocation, float** xformsLocation) {
+ int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType);
+ *indicesLocation = (char*) fPathIndexBuffer.alloc(count * indexBytes,
+ SkChunkAlloc::kThrow_AllocFailType);
+ SkASSERT(SkIsAlign4((uintptr_t)*indicesLocation));
+ memcpy(*indicesLocation, reinterpret_cast<const char*>(indexValues), count * indexBytes);
+
+ const int xformBytes = GrPathRendering::PathTransformSize(transformType) * sizeof(float);
+ *xformsLocation = nullptr;
+
+ if (0 != xformBytes) {
+ *xformsLocation = (float*) fPathTransformBuffer.alloc(count * xformBytes,
+ SkChunkAlloc::kThrow_AllocFailType);
+ SkASSERT(SkIsAlign4((uintptr_t)*xformsLocation));
+ memcpy(*xformsLocation, transformValues, count * xformBytes);
+ }
+ }
+
+ void onDrawBatch(GrBatch*) override;
+
+private:
+ friend class GrInOrderCommandBuilder;
+ friend class GrTargetCommands;
+
+ typedef GrTargetCommands::StateForPathDraw StateForPathDraw;
+
+ StateForPathDraw* allocState(const GrPrimitiveProcessor* primProc = nullptr) {
+ void* allocation = fPipelineBuffer.alloc(sizeof(StateForPathDraw),
+ SkChunkAlloc::kThrow_AllocFailType);
+ return new (allocation) StateForPathDraw(primProc);
+ }
+
+ void unallocState(StateForPathDraw* state) {
+ state->unref();
+ fPipelineBuffer.unalloc(state);
+ }
+
+ void onReset() override;
+ void onFlush() override;
+
+ void onDrawPaths(const GrPathProcessor*,
+ const GrPathRange*,
+ const void* indices,
+ PathIndexType,
+ const float transformValues[],
+ PathTransformType,
+ int count,
+ const GrStencilSettings&,
+ const PipelineInfo&) override;
+
+ bool isIssued(uint32_t drawID) override { return drawID != fDrawID; }
+
+ StateForPathDraw* SK_WARN_UNUSED_RESULT createStateForPathDraw(
+ const GrPrimitiveProcessor*,
+ const PipelineInfo&,
+ GrPipelineOptimizations* opts);
+
+ // TODO: Use a single allocator for commands and records
+ enum {
+ kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's
+ kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms
+ kPipelineBufferMinReserve = 32 * sizeof(StateForPathDraw),
+ };
+
+ // every 100 flushes we should reset our fPipelineBuffer to prevent us from holding at a
+ // highwater mark
+ static const int kPipelineBufferHighWaterMark = 100;
+
+ SkAutoTDelete<GrCommandBuilder> fCommands;
+ SkChunkAlloc fPathIndexBuffer;
+ SkChunkAlloc fPathTransformBuffer;
+ SkChunkAlloc fPipelineBuffer;
+ uint32_t fDrawID;
+ SkAutoTUnref<StateForPathDraw> fPrevState;
+
+ typedef GrClipTarget INHERITED;
+};
+
+#endif
« no previous file with comments | « src/gpu/GrBlurUtils.cpp ('k') | src/gpu/GrBufferedDrawTarget.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698