From c07379d6b1a02ddbf1a5fd9518696b3737067532 Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 20 Nov 2014 14:50:39 -0800 Subject: Adding GeometryData object BUG=skia: Review URL: https://codereview.chromium.org/745663002 --- gyp/gpu.gypi | 1 + src/gpu/GrGeometryData.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/gpu/GrGeometryProcessor.h | 1 + src/gpu/GrProcessor.cpp | 15 +++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 src/gpu/GrGeometryData.h diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index c019b12ea5..4690f62fc2 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -83,6 +83,7 @@ '<(skia_src_path)/gpu/GrFontScaler.cpp', '<(skia_src_path)/gpu/GrFontScaler.h', '<(skia_src_path)/gpu/GrGeometryBuffer.h', + '<(skia_src_path)/gpu/GrGeometryData.h', '<(skia_src_path)/gpu/GrGeometryProcessor.h', '<(skia_src_path)/gpu/GrGlyph.h', '<(skia_src_path)/gpu/GrGpu.cpp', diff --git a/src/gpu/GrGeometryData.h b/src/gpu/GrGeometryData.h new file mode 100644 index 0000000000..a4e9fe6871 --- /dev/null +++ b/src/gpu/GrGeometryData.h @@ -0,0 +1,42 @@ +/* + * Copyright 2014 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGeometryData_DEFINED +#define GrGeometryData_DEFINED + +#include +#include "SkTypes.h" + +/* + * A super lightweight base class for GeometryProcessor's to use to store draw data in a reorderable + * fashion. Its most important feature is a pool allocator. Its virtual, but only so subclasses + * will have their destructors called. + */ + +class GrGeometryData : SkNoncopyable { +public: + virtual ~GrGeometryData() {} + + /** + * Helper for down-casting to a GrGeometryData subclass + */ + template const T& cast() const { return *static_cast(this); } + + void* operator new(size_t size); + + void operator delete(void* target); + + void* operator new(size_t size, void* placement) { + return ::operator new(size, placement); + } + + void operator delete(void* target, void* placement) { + ::operator delete(target, placement); + } +}; + +#endif diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h index 01401ae797..6d27f0b4f1 100644 --- a/src/gpu/GrGeometryProcessor.h +++ b/src/gpu/GrGeometryProcessor.h @@ -8,6 +8,7 @@ #ifndef GrGeometryProcessor_DEFINED #define GrGeometryProcessor_DEFINED +#include "GrGeometryData.h" #include "GrProcessor.h" #include "GrShaderVar.h" diff --git a/src/gpu/GrProcessor.cpp b/src/gpu/GrProcessor.cpp index 01071dabfd..d850d6894a 100644 --- a/src/gpu/GrProcessor.cpp +++ b/src/gpu/GrProcessor.cpp @@ -9,6 +9,7 @@ #include "GrBackendProcessorFactory.h" #include "GrContext.h" #include "GrCoordTransform.h" +#include "GrGeometryData.h" #include "GrInvariantOutput.h" #include "GrMemoryPool.h" #include "SkTLS.h" @@ -152,3 +153,17 @@ bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con } return true; } + +/////////////////////////////////////////////////////////////////////////////////////////////////// + +/* + * GrGeometryData shares the same pool so it lives in this file too + */ +void* GrGeometryData::operator new(size_t size) { + return GrProcessor_Globals::GetTLS()->allocate(size); +} + +void GrGeometryData::operator delete(void* target) { + GrProcessor_Globals::GetTLS()->release(target); +} + -- cgit v1.2.3