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

Unified Diff: src/core/SkInPlace.h

Issue 1153123003: refactor bitmapshader to use a controller (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« src/core/SkBitmapController.cpp ('K') | « src/core/SkBitmapProcState.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkInPlace.h
diff --git a/src/core/SkInPlace.h b/src/core/SkInPlace.h
new file mode 100644
index 0000000000000000000000000000000000000000..02421040f0f770c715bfdc77982a36b79f242928
--- /dev/null
+++ b/src/core/SkInPlace.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkInPlace_DEFINED
+#define SkInPlace_DEFINED
+
+#include "SkTypes.h"
+
+class SkInPlace {
scroggo 2015/06/02 21:17:34 Can we merge this with SkSmallAllocator? It looks
reed2 2015/06/03 02:33:35 SmallAllocator is templated on size, meaning the p
+public:
+ SkInPlace(void* storage, size_t size) : fStorage(storage), fSize(size) {}
+
+ template <typename T> T* create() {
+ if (sizeof(T) <= fSize) {
+ fSize = 0;
+ return new (fStorage) T;
scroggo 2015/06/02 21:17:34 SkNEW_PLACEMENT?
+ } else {
+ return SkNEW(T);
+ }
+ }
+
+ template <typename T, typename A1> T* create(const A1& a1) {
+ if (sizeof(T) <= fSize) {
+ fSize = 0;
+ return new (fStorage) T(a1);
scroggo 2015/06/02 21:17:34 SkNEW_PLACEMENT_ARGS?
+ } else {
+ return SkNEW_ARGS(T, (a1));
+ }
+ }
+
+ template <typename T, typename A1, typename A2> T* create(const A1& a1, const A2& a2) {
+ if (sizeof(T) <= fSize) {
+ fSize = 0;
+ return new (fStorage) T(a1, a1);
+ } else {
+ return SkNEW_ARGS(T, (a1, a2));
+ }
+ }
+
+ template <typename T, typename A1, typename A2, typename A3> T* create(const A1& a1, const A2& a2, const A3& a3) {
scroggo 2015/06/02 21:17:34 nit: line length
+ if (sizeof(T) <= fSize) {
+ fSize = 0;
+ return new (fStorage) T(a1, a2, a3);
+ } else {
+ return SkNEW_ARGS(T, (a1, a2, a3));
+ }
+ }
+
+ template <typename T> void destroy(T* obj) {
+ if (obj) {
+ if ((T*)fStorage == obj) {
+ obj->~T();
+ } else {
+ delete obj;
+ }
+ }
+ }
+
+private:
+ void* fStorage;
+ size_t fSize;
+};
+
+template <size_t SIZE> class SkSInPlace : public SkInPlace {
+public:
+ SkSInPlace() : SkInPlace(fStorage, SIZE) {
+ SkASSERT(SIZE <= sizeof(fStorage));
+ }
+
+private:
+ intptr_t fStorage[(SIZE + (sizeof(intptr_t) - 1)) / sizeof(intptr_t)];
+};
+
+#endif
« src/core/SkBitmapController.cpp ('K') | « src/core/SkBitmapProcState.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698