From 7a89600bac7ab889a5ba8a994c57d677de0e45d5 Mon Sep 17 00:00:00 2001 From: Chris Craik Date: Fri, 19 Feb 2016 15:51:02 -0800 Subject: [PATCH] Add create_trivial_array Change-Id: I5e4236ff59fdaceb95105c5590f4deeda6d0b4c8 --- libs/hwui/LayerBuilder.cpp | 2 +- libs/hwui/RecordingCanvas.cpp | 2 +- libs/hwui/Snapshot.h | 4 ++-- libs/hwui/utils/LinearAllocator.h | 7 +++++++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libs/hwui/LayerBuilder.cpp b/libs/hwui/LayerBuilder.cpp index 1ba3bf26c0d44..c5d7191f1b624 100644 --- a/libs/hwui/LayerBuilder.cpp +++ b/libs/hwui/LayerBuilder.cpp @@ -239,7 +239,7 @@ void LayerBuilder::flushLayerClears(LinearAllocator& allocator) { // put the verts in the frame allocator, since // 1) SimpleRectsOps needs verts, not rects // 2) even if mClearRects stored verts, std::vectors will move their contents - Vertex* const verts = (Vertex*) allocator.alloc(vertCount * sizeof(Vertex)); + Vertex* const verts = (Vertex*) allocator.create_trivial_array(vertCount); Vertex* currentVert = verts; Rect bounds = mClearRects[0]; diff --git a/libs/hwui/RecordingCanvas.cpp b/libs/hwui/RecordingCanvas.cpp index 269e590892d38..5ab2292365165 100644 --- a/libs/hwui/RecordingCanvas.cpp +++ b/libs/hwui/RecordingCanvas.cpp @@ -290,7 +290,7 @@ void RecordingCanvas::drawRect(float left, float top, float right, float bottom, void RecordingCanvas::drawSimpleRects(const float* rects, int vertexCount, const SkPaint* paint) { if (rects == nullptr) return; - Vertex* rectData = (Vertex*) mDisplayList->allocator.alloc(vertexCount * sizeof(Vertex)); + Vertex* rectData = (Vertex*) mDisplayList->allocator.create_trivial_array(vertexCount); Vertex* vertex = rectData; float left = FLT_MAX; diff --git a/libs/hwui/Snapshot.h b/libs/hwui/Snapshot.h index 0ac2f14111406..b03643f06f1c6 100644 --- a/libs/hwui/Snapshot.h +++ b/libs/hwui/Snapshot.h @@ -44,7 +44,7 @@ namespace uirenderer { */ class RoundRectClipState { public: - /** static void* operator new(size_t size); PURPOSELY OMITTED, allocator only **/ + static void* operator new(size_t size) = delete; static void* operator new(size_t size, LinearAllocator& allocator) { return allocator.alloc(size); } @@ -65,7 +65,7 @@ public: class ProjectionPathMask { public: - /** static void* operator new(size_t size); PURPOSELY OMITTED, allocator only **/ + static void* operator new(size_t size) = delete; static void* operator new(size_t size, LinearAllocator& allocator) { return allocator.alloc(size); } diff --git a/libs/hwui/utils/LinearAllocator.h b/libs/hwui/utils/LinearAllocator.h index 0a0e1858cd91c..34c8c6beea81c 100644 --- a/libs/hwui/utils/LinearAllocator.h +++ b/libs/hwui/utils/LinearAllocator.h @@ -84,6 +84,13 @@ public: return new (allocImpl(sizeof(T))) T(std::forward(params)...); } + template + T* create_trivial_array(int count) { + static_assert(std::is_trivially_destructible::value, + "Error, called create_trivial_array on a non-trivial type"); + return reinterpret_cast(allocImpl(sizeof(T) * count)); + } + /** * Attempt to deallocate the given buffer, with the LinearAllocator attempting to rewind its * state if possible.