aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkVertices.h
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-03-16 16:44:25 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-16 16:44:39 +0000
commit0c492cfe1713d6895d1d513e754d938ff0faa5e5 (patch)
tree5ee051971ec9eb1013d0b9db5ff7e019f50f618e /include/core/SkVertices.h
parent3fe326114a93edf8cd44fc8a4b652ee6815cd9cb (diff)
Revert[3] "store vertices arrays inline with object"""
This reverts commit 7d9f9e30204ee8a380443b868e4cc281319a2051. Reason for revert: speculative revert to try to fix google3 Original change's description: > Revert[2] "store vertices arrays inline with object"" > > This reverts commit 9e62df6ecd1000860ad19ab9425579dfb7002ba0. > > Reason for revert: behavior in reader32 fixed > > Fix is here: https://skia-review.googlesource.com/c/9729/ > > Original change's description: > > Revert "store vertices arrays inline with object" > > > > This reverts commit eaaebb19a17d213355e7a70e0cfabe4ba61929d4. > > > > Reason for revert: may call SkReader32::read(null, 0) -- reader needs to handle this > > > > Original change's description: > > > store vertices arrays inline with object > > > > > > Also unify some of naming (esp. around texCoords) > > > > > > BUG=skia:6366 > > > > > > Change-Id: I5a6793f029cccf0cd0a2c1d180b259ce4eab526f > > > Reviewed-on: https://skia-review.googlesource.com/9705 > > > Commit-Queue: Mike Reed <reed@google.com> > > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > > > > > > TBR=bsalomon@google.com,reed@google.com,reviews@skia.org > > NOPRESUBMIT=true > > NOTREECHECKS=true > > NOTRY=true > > BUG=skia:6366 > > > > Change-Id: Ie421654bcd74d74f8be6676291e3d6e16e2a7a16 > > Reviewed-on: https://skia-review.googlesource.com/9727 > > Reviewed-by: Mike Reed <reed@google.com> > > Commit-Queue: Mike Reed <reed@google.com> > > > > TBR=bsalomon@google.com,reviews@skia.org,reed@google.com > NOPRESUBMIT=true > NOTREECHECKS=true > NOTRY=true > BUG=skia:6366 > > Change-Id: I1f12108fff8f551d66455cfadd6d5dd9412e9aa8 > Reviewed-on: https://skia-review.googlesource.com/9760 > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Mike Reed <reed@google.com> > TBR=bsalomon@google.com,reviews@skia.org,reed@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia:6366 Change-Id: Ie23130a07fbecd5664e37291bc167008a6b496bc Reviewed-on: https://skia-review.googlesource.com/9806 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'include/core/SkVertices.h')
-rw-r--r--include/core/SkVertices.h97
1 files changed, 40 insertions, 57 deletions
diff --git a/include/core/SkVertices.h b/include/core/SkVertices.h
index 8d6f211a45..af4e3bc960 100644
--- a/include/core/SkVertices.h
+++ b/include/core/SkVertices.h
@@ -16,10 +16,14 @@
#include "SkRefCnt.h"
/**
- * An immutable set of vertex data that can be used with SkCanvas::drawVertices.
+ * An immutable set of vertex data that can be used with SkCanvas::drawVertices. Clients are
+ * encouraged to provide a bounds on the vertex positions if they can compute one more cheaply than
+ * looping over the positions.
*/
class SkVertices : public SkNVRefCnt<SkVertices> {
public:
+ ~SkVertices() { sk_free((void*)fPositions); }
+
/**
* Create a vertices by copying the specified arrays. texs and colors may be nullptr,
* and indices is ignored if indexCount == 0.
@@ -38,93 +42,72 @@ public:
return MakeCopy(mode, vertexCount, positions, texs, colors, 0, nullptr);
}
- struct Sizes;
-
- enum BuilderFlags {
- kHasTexCoords_BuilderFlag = 1 << 0,
- kHasColors_BuilderFlag = 1 << 1,
+ enum Flags {
+ kHasTexs_Flag = 1 << 0,
+ kHasColors_Flag = 1 << 1,
};
class Builder {
public:
Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount, uint32_t flags);
+ ~Builder();
- bool isValid() const { return fVertices != nullptr; }
+ bool isValid() const { return fPositions != nullptr; }
- // if the builder is invalid, these will return 0
- int vertexCount() const;
- int indexCount() const;
- SkPoint* positions();
- SkPoint* texCoords(); // returns null if there are no texCoords
- SkColor* colors(); // returns null if there are no colors
- uint16_t* indices(); // returns null if there are no indices
+ int vertexCount() const { return fVertexCnt; }
+ int indexCount() const { return fIndexCnt; }
+ SkPoint* positions() { return fPositions; }
+ SkPoint* texCoords() { return fTexs; }
+ SkColor* colors() { return fColors; }
+ uint16_t* indices() { return fIndices; }
- // Detach the built vertices object. After the first call, this will always return null.
sk_sp<SkVertices> detach();
private:
- Builder(SkCanvas::VertexMode mode, int vertexCount, int indexCount, const Sizes&);
-
- void init(SkCanvas::VertexMode mode, int vertexCount, int indexCount, const Sizes&);
-
- // holds a partially complete object. only completed in detach()
- sk_sp<SkVertices> fVertices;
-
- friend class SkVertices;
+ SkPoint* fPositions; // owner of storage, use sk_free
+ SkPoint* fTexs;
+ SkColor* fColors;
+ uint16_t* fIndices;
+ int fVertexCnt;
+ int fIndexCnt;
+ SkCanvas::VertexMode fMode;
};
- uint32_t uniqueID() const { return fUniqueID; }
SkCanvas::VertexMode mode() const { return fMode; }
- const SkRect& bounds() const { return fBounds; }
-
- bool hasColors() const { return SkToBool(this->colors()); }
- bool hasTexCoords() const { return SkToBool(this->texCoords()); }
- bool hasIndices() const { return SkToBool(this->indices()); }
+ uint32_t uniqueID() const { return fUniqueID; }
int vertexCount() const { return fVertexCnt; }
+ bool hasColors() const { return SkToBool(fColors); }
+ bool hasTexCoords() const { return SkToBool(fTexs); }
const SkPoint* positions() const { return fPositions; }
const SkPoint* texCoords() const { return fTexs; }
const SkColor* colors() const { return fColors; }
+ bool isIndexed() const { return SkToBool(fIndexCnt); }
int indexCount() const { return fIndexCnt; }
const uint16_t* indices() const { return fIndices; }
- // returns approximate byte size of the vertices object
- size_t approximateSize() const;
+ size_t size() const {
+ return fVertexCnt * (sizeof(SkPoint) * (this->hasTexCoords() ? 2 : 1) + sizeof(SkColor)) +
+ fIndexCnt * sizeof(uint16_t);
+ }
- /**
- * Recreate a vertices from a buffer previously created by calling encode().
- * Returns null if the data is corrupt or the length is incorrect for the contents.
- */
- static sk_sp<SkVertices> Decode(const void* buffer, size_t length);
+ const SkRect& bounds() const { return fBounds; }
- /**
- * Pack the vertices object into a byte buffer. This can be used to recreate the vertices
- * by calling Decode() with the buffer.
- */
+ static sk_sp<SkVertices> Decode(const void*, size_t);
sk_sp<SkData> encode() const;
private:
SkVertices() {}
- static sk_sp<SkVertices> Alloc(int vCount, int iCount, uint32_t builderFlags,
- size_t* arraySize);
-
- // we store this first, to pair with the refcnt in our base-class, so we don't have an
- // unnecessary pad between it and the (possibly 8-byte aligned) ptrs.
+ const SkPoint* fPositions; // owner of storage, use sk_free
+ const SkPoint* fTexs;
+ const SkColor* fColors;
+ const uint16_t* fIndices;
+ SkRect fBounds;
uint32_t fUniqueID;
-
- // these point inside our allocation, so none of these can be "freed"
- SkPoint* fPositions;
- SkPoint* fTexs;
- SkColor* fColors;
- uint16_t* fIndices;
-
- SkRect fBounds; // computed to be the union of the fPositions[]
- int fVertexCnt;
- int fIndexCnt;
-
+ int fVertexCnt;
+ int fIndexCnt;
SkCanvas::VertexMode fMode;
- // below here is where the actual array data is stored.
};
#endif