diff options
author | 2018-05-21 09:10:53 -0600 | |
---|---|---|
committer | 2018-05-21 21:52:54 +0000 | |
commit | 4bfb50b904e0e92d10145398eb3a6f8dd7868867 (patch) | |
tree | d25bb829a4e5787b423df0c5e19721a8ca48f438 /src/gpu/ccpr/GrCCSTLList.h | |
parent | bc721ba4be626e3ba753f55341a7019d98044102 (diff) |
ccpr: Abstract the draws list in a separate class
Bug: skia:
Change-Id: I583c1bdc470e5830d041955d14b164fc00d5d014
Reviewed-on: https://skia-review.googlesource.com/129227
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/ccpr/GrCCSTLList.h')
-rw-r--r-- | src/gpu/ccpr/GrCCSTLList.h | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/gpu/ccpr/GrCCSTLList.h b/src/gpu/ccpr/GrCCSTLList.h new file mode 100644 index 0000000000..3b478e9842 --- /dev/null +++ b/src/gpu/ccpr/GrCCSTLList.h @@ -0,0 +1,61 @@ +/* + * Copyright 2018 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrCCSTLList_DEFINED +#define GrCCSTLList_DEFINED + +#include "SkArenaAlloc.h" + +/** + * A singly-linked list whose head element is a local class member. This is required by + * GrCCDrawPathsOp because the owning opList is unknown at the time of creation, so we can't use its + * associated allocator to create the first element. + */ +template<typename T> class GrCCSTLList { +public: + GrCCSTLList(T&& head) : fHead(std::move(head)) {} + + ~GrCCSTLList() { + T* draw = fHead.fNext; // fHead will be destructed automatically. + while (draw) { + T* next = draw->fNext; + draw->~T(); + draw = next; + } + } + + const T& head() const { return fHead; } + T& head() { return fHead; } + + void append(GrCCSTLList&& right, SkArenaAlloc* alloc) { + T* nextTail = (&right.fHead == right.fTail) ? nullptr : right.fTail; + T* newRightHead = + new (alloc->makeBytesAlignedTo(sizeof(T), alignof(T))) T(std::move(right.fHead)); + + // Finish the move of right.fHead. + right.fHead.fNext = nullptr; + right.fTail = &right.fHead; + + fTail->fNext = newRightHead; + fTail = !nextTail ? newRightHead : nextTail; + } + + struct Iter { + bool operator!=(const Iter& that) { return fCurr != that.fCurr; } + const T& operator*() { return *fCurr; } + void operator++() { fCurr = fCurr->fNext; } + const T* fCurr; + }; + Iter begin() const { return Iter{&fHead}; } + Iter end() const { return Iter{nullptr}; } + +private: + T fHead; + T* fTail = &fHead; +}; + +#endif |