Add placement new macros to SkPostConfig, call SkNEW* from Ganesh.
authortomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 9 Jul 2012 20:17:56 +0000 (20:17 +0000)
committertomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 9 Jul 2012 20:17:56 +0000 (20:17 +0000)
TODO: unify with the placement new implementation in SkTemplatesPriv.h,
once various issues there are overcome. reed@ should be taking the lead
there.

http://codereview.appspot.com/6384043/

git-svn-id: http://skia.googlecode.com/svn/trunk@4492 2bbb7eff-a529-9590-31e7-b0007b416f81

30 files changed:
include/core/SkPostConfig.h
include/gpu/GrContextFactory.h
include/gpu/GrProgramStageFactory.h
src/gpu/GrAAHairLinePathRenderer.cpp
src/gpu/GrAddPathRenderers_default.cpp
src/gpu/GrAllocator.h
src/gpu/GrAtlas.cpp
src/gpu/GrClipMaskManager.h
src/gpu/GrContext.cpp
src/gpu/GrGpu.cpp
src/gpu/GrGpuFactory.cpp
src/gpu/GrPathRendererChain.cpp
src/gpu/GrPlotMgr.h
src/gpu/GrRectanizer.cpp
src/gpu/GrRectanizer_fifo.cpp
src/gpu/GrRedBlackTree.h
src/gpu/GrResourceCache.cpp
src/gpu/GrStencilAndCoverPathRenderer.cpp
src/gpu/GrTextContext.cpp
src/gpu/GrTextStrike.cpp
src/gpu/SkGpuCanvas.cpp
src/gpu/SkGpuDevice.cpp
src/gpu/SkGrFontScaler.cpp
src/gpu/SkGrPixelRef.cpp
src/gpu/app-android.cpp
src/gpu/gl/GrGLCreateNullInterface.cpp
src/gpu/gl/GrGLTexture.cpp
src/gpu/gl/GrGpuGL.cpp
src/gpu/gl/GrGpuGL_unittest.cpp
src/gpu/gr_hello_world.cpp

index 8d52f70..90caf7f 100644 (file)
@@ -85,6 +85,9 @@
     #define SkNEW(type_name)                new type_name
     #define SkNEW_ARGS(type_name, args)     new type_name args
     #define SkNEW_ARRAY(type_name, count)   new type_name[count]
+    #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name
+    #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
+                                            new (buf) type_name args
     #define SkDELETE(obj)                   delete obj
     #define SkDELETE_ARRAY(array)           delete[] array
 #endif
index 0a66274..65bf597 100644 (file)
@@ -68,23 +68,23 @@ public:
         SkAutoTUnref<GrContext> grCtx;
         switch (type) {
             case kNative_GLContextType:
-                glCtx.reset(new SkNativeGLContext());
+                glCtx.reset(SkNEW(SkNativeGLContext));
                 break;
 #ifdef SK_ANGLE
             case kANGLE_GLContextType:
-                glCtx.reset(new SkANGLEGLContext());
+                glCtx.reset(SkNEW(SkANGLEGLContext));
                 break;
 #endif
 #ifdef SK_MESA
             case kMESA_GLContextType:
-                glCtx.reset(new SkMesaGLContext());
+                glCtx.reset(SkNEW(SkMesaGLContext));
                 break;
 #endif
             case kNull_GLContextType:
-                glCtx.reset(new SkNullGLContext());
+                glCtx.reset(SkNEW(SkNullGLContext));
                 break;
             case kDebug_GLContextType:
-                glCtx.reset(new SkDebugGLContext());
+                glCtx.reset(SkNEW(SkDebugGLContext));
                 break;
         }
         static const int kBogusSize = 1;
index c01b3f0..d133beb 100644 (file)
@@ -95,7 +95,7 @@ public:
      the object. */
     virtual GLProgramStage* createGLInstance(
                         const GrCustomStage& stage) const SK_OVERRIDE {
-        return new GLProgramStage(*this, stage);
+        return SkNEW_ARGS(GLProgramStage, (*this, stage));
     }
 
     /** This class is a singleton. This function returns the single instance.
@@ -104,7 +104,8 @@ public:
         static SkAlignedSTStorage<1, GrTProgramStageFactory> gInstanceMem;
         static const GrTProgramStageFactory* gInstance;
         if (!gInstance) {
-            gInstance = new (gInstanceMem.get()) GrTProgramStageFactory();
+            gInstance = SkNEW_PLACEMENT(gInstanceMem.get(),
+                                        GrTProgramStageFactory);
         }
         return *gInstance;
     }
index 2b8c7c1..8aed4b0 100644 (file)
@@ -35,7 +35,7 @@ bool push_quad_index_data(GrIndexBuffer* qIdxBuffer) {
     uint16_t* data = (uint16_t*) qIdxBuffer->lock();
     bool tempData = NULL == data;
     if (tempData) {
-        data = new uint16_t[kNumQuadsInIdxBuffer * kIdxsPerQuad];
+        data = SkNEW_ARRAY(uint16_t, kNumQuadsInIdxBuffer * kIdxsPerQuad);
     }
     for (int i = 0; i < kNumQuadsInIdxBuffer; ++i) {
 
@@ -86,9 +86,8 @@ GrPathRenderer* GrAAHairLinePathRenderer::Create(GrContext* context) {
         !push_quad_index_data(qIdxBuf)) {
         return NULL;
     }
-    return new GrAAHairLinePathRenderer(context,
-                                        lIdxBuffer,
-                                        qIdxBuf);
+    return SkNEW_ARGS(GrAAHairLinePathRenderer,
+                      (context, lIdxBuffer, qIdxBuf));
 }
 
 GrAAHairLinePathRenderer::GrAAHairLinePathRenderer(
index 32b2a07..24f1017 100644 (file)
@@ -23,6 +23,6 @@ void GrPathRenderer::AddPathRenderers(GrContext* ctx,
         if (GrPathRenderer* pr = GrAAHairLinePathRenderer::Create(ctx)) {
             chain->addPathRenderer(pr)->unref();
         }
-        chain->addPathRenderer(new GrAAConvexPathRenderer())->unref();
+        chain->addPathRenderer(SkNEW(GrAAConvexPathRenderer))->unref();
     }
 }
index f333d42..ae456cd 100755 (executable)
@@ -163,14 +163,14 @@ public:
     T& push_back() {
         void* item = fAllocator.push_back();
         GrAssert(NULL != item);
-        new (item) T;
+        SkNEW_PLACEMENT(item, T);
         return *(T*)item;
     }
 
     T& push_back(const T& t) {
         void* item = fAllocator.push_back();
         GrAssert(NULL != item);
-        new (item) T(t);
+        SkNEW_PLACEMENT_ARGS(item, T, (t));
         return *(T*)item;
     }
 
index fb12719..2b76d13 100644 (file)
@@ -131,7 +131,7 @@ GrAtlasMgr::GrAtlasMgr(GrGpu* gpu) {
     fGpu = gpu;
     gpu->ref();
     Gr_bzero(fTexture, sizeof(fTexture));
-    fPlotMgr = new GrPlotMgr(GR_PLOT_WIDTH, GR_PLOT_HEIGHT);
+    fPlotMgr = SkNEW_ARGS(GrPlotMgr, (GR_PLOT_WIDTH, GR_PLOT_HEIGHT));
 }
 
 GrAtlasMgr::~GrAtlasMgr() {
@@ -189,7 +189,7 @@ GrAtlas* GrAtlasMgr::addToAtlas(GrAtlas* atlas,
         }
     }
 
-    GrAtlas* newAtlas = new GrAtlas(this, plot.fX, plot.fY, format);
+    GrAtlas* newAtlas = SkNEW_ARGS(GrAtlas, (this, plot.fX, plot.fY, format));
     if (!newAtlas->addSubImage(width, height, image, loc)) {
         delete newAtlas;
         return NULL;
index bb597ba..8106185 100644 (file)
@@ -38,7 +38,7 @@ public:
     , fStack(sizeof(GrClipStackFrame)) {
         // We need an initial frame to capture the clip state prior to 
         // any pushes
-        new (fStack.push_back()) GrClipStackFrame();
+        SkNEW_PLACEMENT(fStack.push_back(), GrClipStackFrame);
     }
 
     ~GrClipMaskCache() {
@@ -87,7 +87,7 @@ public:
      * reduce the mask creation cost?
      */
     void push() {
-        new (fStack.push_back()) GrClipStackFrame();
+        SkNEW_PLACEMENT(fStack.push_back(), GrClipStackFrame);
     }
 
     void pop() {
index 6326f4d..f79249c 100644 (file)
@@ -66,7 +66,7 @@ GrContext* GrContext::Create(GrEngine engine,
     GrContext* ctx = NULL;
     GrGpu* fGpu = GrGpu::Create(engine, context3D);
     if (NULL != fGpu) {
-        ctx = new GrContext(fGpu);
+        ctx = SkNEW_ARGS(GrContext, (fGpu));
         fGpu->unref();
     }
     return ctx;
@@ -74,7 +74,7 @@ GrContext* GrContext::Create(GrEngine engine,
 
 namespace {
 void* CreateThreadInstanceCount() {
-    return new int(0);
+    return SkNEW_ARGS(int, (0));
 }
 void DeleteThreadInstanceCount(void* v) {
     delete reinterpret_cast<int*>(v);
@@ -244,7 +244,7 @@ void apply_morphology(GrGpu* gpu,
     sampleM.setIDiv(texture->width(), texture->height());
     drawState->sampler(0)->reset(sampleM);
     SkAutoTUnref<GrCustomStage> morph(
-        new GrMorphologyEffect(direction, radius, morphType));
+        SkNEW_ARGS(GrMorphologyEffect, (direction, radius, morphType)));
     drawState->sampler(0)->setCustomStage(morph);
     drawState->setTexture(0, texture);
     gpu->drawSimpleRect(rect, NULL, 1 << 0);
@@ -263,8 +263,8 @@ void convolve_gaussian(GrGpu* gpu,
     GrMatrix sampleM;
     sampleM.setIDiv(texture->width(), texture->height());
     drawState->sampler(0)->reset(sampleM);
-    SkAutoTUnref<GrConvolutionEffect> conv(new
-        GrConvolutionEffect(direction, radius));
+    SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
+                                                      (direction, radius)));
     conv->setGaussianKernel(sigma);
     drawState->sampler(0)->setCustomStage(conv);
     drawState->setTexture(0, texture);
@@ -1682,7 +1682,8 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
                                            bool allowSW) {
     if (NULL == fPathRendererChain) {
         fPathRendererChain = 
-            new GrPathRendererChain(this, GrPathRendererChain::kNone_UsageFlag);
+            SkNEW_ARGS(GrPathRendererChain,
+                       (this, GrPathRendererChain::kNone_UsageFlag));
     }
 
     GrPathRenderer* pr = fPathRendererChain->getPathRenderer(path, fill,
@@ -1691,7 +1692,7 @@ GrPathRenderer* GrContext::getPathRenderer(const SkPath& path,
 
     if (NULL == pr && allowSW) {
         if (NULL == fSoftwarePathRenderer) {
-            fSoftwarePathRenderer = new GrSoftwarePathRenderer(this);
+            fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this));
         }
 
         pr = fSoftwarePathRenderer;
@@ -1751,15 +1752,16 @@ GrContext::GrContext(GrGpu* gpu) {
     fGpu->ref();
     fGpu->setContext(this);
 
-    fDrawState = new GrDrawState();
+    fDrawState = SkNEW(GrDrawState);
     fGpu->setDrawState(fDrawState);
 
     fPathRendererChain = NULL;
     fSoftwarePathRenderer = NULL;
 
-    fTextureCache = new GrResourceCache(MAX_TEXTURE_CACHE_COUNT,
-                                        MAX_TEXTURE_CACHE_BYTES);
-    fFontCache = new GrFontCache(fGpu);
+    fTextureCache = SkNEW_ARGS(GrResourceCache,
+                               (MAX_TEXTURE_CACHE_COUNT,
+                                MAX_TEXTURE_CACHE_BYTES));
+    fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
 
     fLastDrawCategory = kUnbuffered_DrawCategory;
 
@@ -1767,7 +1769,7 @@ GrContext::GrContext(GrGpu* gpu) {
     fDrawBufferVBAllocPool = NULL;
     fDrawBufferIBAllocPool = NULL;
 
-    fAARectRenderer = new GrAARectRenderer;
+    fAARectRenderer = SkNEW(GrAARectRenderer);
 
     this->setupDrawBuffer();
 }
@@ -1780,17 +1782,17 @@ void GrContext::setupDrawBuffer() {
 
 #if DEFER_TEXT_RENDERING || BATCH_RECT_TO_RECT || DEFER_PATHS
     fDrawBufferVBAllocPool =
-        new GrVertexBufferAllocPool(fGpu, false,
+        SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false,
                                     DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
-                                    DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS);
+                                    DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS));
     fDrawBufferIBAllocPool =
-        new GrIndexBufferAllocPool(fGpu, false,
+        SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false,
                                    DRAW_BUFFER_IBPOOL_BUFFER_SIZE,
-                                   DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS);
+                                   DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS));
 
-    fDrawBuffer = new GrInOrderDrawBuffer(fGpu,
+    fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
                                           fDrawBufferVBAllocPool,
-                                          fDrawBufferIBAllocPool);
+                                          fDrawBufferIBAllocPool));
 #endif
 
 #if BATCH_RECT_TO_RECT
index 71e341b..0385b25 100644 (file)
@@ -466,9 +466,9 @@ void GrGpu::finalizeReservedIndices() {
 void GrGpu::prepareVertexPool() {
     if (NULL == fVertexPool) {
         GrAssert(0 == fVertexPoolUseCnt);
-        fVertexPool = new GrVertexBufferAllocPool(this, true,
+        fVertexPool = SkNEW_ARGS(GrVertexBufferAllocPool, (this, true,
                                                   VERTEX_POOL_VB_SIZE,
-                                                  VERTEX_POOL_VB_COUNT);
+                                                  VERTEX_POOL_VB_COUNT));
         fVertexPool->releaseGpuRef();
     } else if (!fVertexPoolUseCnt) {
         // the client doesn't have valid data in the pool
@@ -479,9 +479,9 @@ void GrGpu::prepareVertexPool() {
 void GrGpu::prepareIndexPool() {
     if (NULL == fIndexPool) {
         GrAssert(0 == fIndexPoolUseCnt);
-        fIndexPool = new GrIndexBufferAllocPool(this, true,
+        fIndexPool = SkNEW_ARGS(GrIndexBufferAllocPool, (this, true,
                                                 INDEX_POOL_IB_SIZE,
-                                                INDEX_POOL_IB_COUNT);
+                                                INDEX_POOL_IB_COUNT));
         fIndexPool->releaseGpuRef();
     } else if (!fIndexPoolUseCnt) {
         // the client doesn't have valid data in the pool
index 4a9bcf6..0d4c381 100644 (file)
@@ -36,7 +36,7 @@ GrGpu* GrGpu::Create(GrEngine engine, GrPlatform3DContext context3D) {
         }
         GrGLContextInfo ctxInfo(glInterface);
         if (ctxInfo.isInitialized()) {
-            return new GrGpuGL(ctxInfo);
+            return SkNEW_ARGS(GrGpuGL, (ctxInfo));
         }
     }
     return NULL;
index 648225e..038f836 100644 (file)
@@ -54,6 +54,7 @@ void GrPathRendererChain::init() {
     bool twoSided = gpu->getCaps().fTwoSidedStencilSupport;
     bool wrapOp = gpu->getCaps().fStencilWrapOpsSupport;
     GrPathRenderer::AddPathRenderers(fOwner, fFlags, this);
-    this->addPathRenderer(new GrDefaultPathRenderer(twoSided, wrapOp))->unref();
+    this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
+                                     (twoSided, wrapOp)))->unref();
     fInit = true;
 }
index 0e631a9..38589f3 100644 (file)
@@ -22,7 +22,7 @@ public:
         if (needed <= sizeof(fStorage)) {
             fBusy = fStorage;
         } else {
-            fBusy = new char[needed];
+            fBusy = SkNEW_ARRAY(char, needed);
         }
         this->reset();
     }
index 628b890..8df3b05 100644 (file)
@@ -117,7 +117,7 @@ bool GrRectanizerPow2::addRect(int width, int height, GrIPoint16* loc) {
 ///////////////////////////////////////////////////////////////////////////////
 
 GrRectanizer* GrRectanizer::Factory(int width, int height) {
-    return new GrRectanizerPow2(width, height);
+    return SkNEW_ARGS(GrRectanizerPow2, (width, height));
 }
 
 
index 3bfc46f..0f412b8 100644 (file)
@@ -117,7 +117,7 @@ bool GrRectanizerFIFO::addRect(int width, int height, GrIPoint16* loc) {
 ///////////////////////////////////////////////////////////////////////////////
 
 GrRectanizer* GrRectanizer::Factory(int width, int height) {
-    return new GrRectanizerFIFO(width, height);
+    return SkNEW_ARGS(GrRectanizerFIFO, (width, height));
 }
 
 
index da5ae3e..8187d81 100644 (file)
@@ -343,7 +343,7 @@ typename GrRedBlackTree<T,C>::Iter GrRedBlackTree<T,C>::insert(const T& t) {
 
     ++fCount;
 
-    Node* x = new Node;
+    Node* x = SkNEW(Node);
     x->fChildren[kLeft_Child] = NULL;
     x->fChildren[kRight_Child] = NULL;
     x->fItem = t;
index 633cd23..b82cdb2 100644 (file)
@@ -190,7 +190,7 @@ GrResourceEntry* GrResourceCache::create(const GrResourceKey& key,
     GrAssert(!fPurging);
     GrAutoResourceCacheValidate atcv(this);
 
-    GrResourceEntry* entry = new GrResourceEntry(key, resource);
+    GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource));
 
     if (lock) {
         // mark the entry as "busy" so it doesn't get purged
index 81dc1db..a138857 100644 (file)
@@ -16,7 +16,7 @@ GrPathRenderer* GrStencilAndCoverPathRenderer::Create(GrContext* context) {
     GrAssert(NULL != context);
     GrAssert(NULL != context->getGpu());
     if (context->getGpu()->getCaps().fPathStencilingSupport) {
-        return new GrStencilAndCoverPathRenderer(context->getGpu());
+        return SkNEW_ARGS(GrStencilAndCoverPathRenderer, (context->getGpu()));
     } else {
         return NULL;
     }
index d642f13..93ef23d 100644 (file)
@@ -209,7 +209,7 @@ void GrTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
         }
 
         if (NULL == glyph->fPath) {
-            SkPath* path = new SkPath;
+            SkPath* path = SkNEW(SkPath);
             if (!scaler->getGlyphPath(glyph->glyphID(), path)) {
                 // flag the glyph as being dead?
                 delete path;
index e61c46e..aebaaf8 100644 (file)
@@ -36,10 +36,11 @@ GrFontCache::~GrFontCache() {
 GrTextStrike* GrFontCache::generateStrike(GrFontScaler* scaler,
                                           const Key& key) {
     if (NULL == fAtlasMgr) {
-        fAtlasMgr = new GrAtlasMgr(fGpu);
+        fAtlasMgr = SkNEW_ARGS(GrAtlasMgr, (fGpu));
     }
-    GrTextStrike* strike = new GrTextStrike(this, scaler->getKey(),
-                                            scaler->getMaskFormat(), fAtlasMgr);
+    GrTextStrike* strike = SkNEW_ARGS(GrTextStrike,
+                                      (this, scaler->getKey(),
+                                       scaler->getMaskFormat(), fAtlasMgr));
     fCache.insert(key, strike);
 
     if (fHead) {
index fa57335..55880a6 100644 (file)
@@ -20,7 +20,7 @@ SkGpuCanvas::SkGpuCanvas(GrContext* context, GrRenderTarget* renderTarget) {
     fContext = context;
     fContext->ref();
 
-    this->setDevice(new SkGpuDevice(context, renderTarget))->unref();
+    this->setDevice(SkNEW_ARGS(SkGpuDevice, (context, renderTarget)))->unref();
 }
 
 SkGpuCanvas::~SkGpuCanvas() {
index 491e273..fc73f0d 100644 (file)
@@ -194,9 +194,9 @@ void SkGpuDevice::initFromRenderTarget(GrContext* context,
     // are ensuring that both objects will live as long as the pixel ref.
     SkPixelRef* pr;
     if (fTexture) {
-        pr = new SkGrTexturePixelRef(fTexture);
+        pr = SkNEW_ARGS(SkGrTexturePixelRef, (fTexture));
     } else {
-        pr = new SkGrRenderTargetPixelRef(fRenderTarget);
+        pr = SkNEW_ARGS(SkGrRenderTargetPixelRef, (fRenderTarget));
     }
     this->setPixelRef(pr, 0)->unref();
 }
@@ -237,7 +237,7 @@ SkGpuDevice::SkGpuDevice(GrContext* context,
         GrAssert(NULL != fRenderTarget);
 
         // wrap the bitmap with a pixelref to expose our texture
-        SkGrTexturePixelRef* pr = new SkGrTexturePixelRef(fTexture);
+        SkGrTexturePixelRef* pr = SkNEW_ARGS(SkGrTexturePixelRef, (fTexture));
         this->setPixelRef(pr, 0)->unref();
     } else {
         GrPrintf("--- failed to create gpu-offscreen [%d %d]\n",
@@ -533,25 +533,25 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
     GrSamplerState* sampler = grPaint->textureSampler(kShaderTextureIdx);
     switch (bmptype) {
         case SkShader::kRadial_BitmapType:
-            sampler->setCustomStage(new GrRadialGradient())->unref();
+            sampler->setCustomStage(SkNEW(GrRadialGradient))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kSweep_BitmapType:
-            sampler->setCustomStage(new GrSweepGradient())->unref();
+            sampler->setCustomStage(SkNEW(GrSweepGradient))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kTwoPointRadial_BitmapType:
-            sampler->setCustomStage(new
-                GrRadial2Gradient(twoPointParams[0],
-                                  twoPointParams[1],
-                                  twoPointParams[2] < 0))->unref();
+            sampler->setCustomStage(SkNEW_ARGS(GrRadial2Gradient,
+                         (twoPointParams[0],
+                          twoPointParams[1],
+                          twoPointParams[2] < 0)))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         case SkShader::kTwoPointConical_BitmapType:
-            sampler->setCustomStage(new
-                GrConical2Gradient(twoPointParams[0],
-                                   twoPointParams[1],
-                                   twoPointParams[2]))->unref();
+            sampler->setCustomStage(SkNEW_ARGS(GrConical2Gradient,
+                                               (twoPointParams[0],
+                                                twoPointParams[1],
+                                                twoPointParams[2])))->unref();
             sampler->setFilter(GrSamplerState::kBilinear_Filter);
             break;
         default:
@@ -1596,7 +1596,8 @@ bool SkGpuDevice::filterImage(SkImageFilter* filter, const SkBitmap& src,
                                  SkIntToScalar(src.height()));
     GrTexture* resultTexture = filter_texture(fContext, texture, filter, rect);
     if (resultTexture) {
-        result->setPixelRef(new SkGrTexturePixelRef(resultTexture))->unref();
+        result->setPixelRef(SkNEW_ARGS(SkGrTexturePixelRef,
+                                       (resultTexture)))->unref();
         resultTexture->unref();
     }
     return true;
@@ -1681,7 +1682,7 @@ static GrFontScaler* get_gr_font_scaler(SkGlyphCache* cache) {
         scaler = (GrFontScaler*)auxData;
     }
     if (NULL == scaler) {
-        scaler = new SkGrFontScaler(cache);
+        scaler = SkNEW_ARGS(SkGrFontScaler, (cache));
         cache->setAuxProc(GlyphCacheAuxProc, scaler);
     }
     return scaler;
@@ -1710,7 +1711,7 @@ SkDrawProcs* SkGpuDevice::initDrawForText(GrTextContext* context) {
 
     // deferred allocation
     if (NULL == fDrawProcs) {
-        fDrawProcs = new GrSkDrawProcs;
+        fDrawProcs = SkNEW(GrSkDrawProcs);
         fDrawProcs->fD1GProc = SkGPU_Draw1Glyph;
         fDrawProcs->fContext = fContext;
     }
index 430b599..26412f4 100644 (file)
@@ -95,7 +95,7 @@ GrMaskFormat SkGrFontScaler::getMaskFormat() {
 
 const GrKey* SkGrFontScaler::getKey() {
     if (NULL == fKey) {
-        fKey = new SkGrDescKey(fStrike->getDescriptor());
+        fKey = SkNEW_ARGS(SkGrDescKey, (fStrike->getDescriptor()));
     }
     return fKey;
 }
index 7280a64..7e0e2cd 100644 (file)
@@ -81,7 +81,7 @@ static SkGrPixelRef* copyToTexturePixelRef(GrTexture* texture,
     dst->releaseRenderTarget();
 #endif
 
-    SkGrPixelRef* pixelRef = new SkGrPixelRef(dst);
+    SkGrPixelRef* pixelRef = SkNEW_ARGS(SkGrPixelRef, (dst));
     GrSafeUnref(dst);
     return pixelRef;
 }
index 2dad1f9..56a96a6 100644 (file)
@@ -246,7 +246,7 @@ void State::applyMatrix(SkCanvas* canvas) {
 static State* get_state() {
     static State* gState;
     if (NULL == gState) {
-        gState = new State;
+        gState = SkNEW(State);
     }
     return gState;
 }
index b9a3c5e..6451fca 100644 (file)
@@ -388,7 +388,7 @@ const GrGLInterface* GrGLCreateNullInterface() {
     // interface
     static SkAutoTUnref<GrGLInterface> glInterface;
     if (!glInterface.get()) {
-        GrGLInterface* interface = new GrGLInterface;
+        GrGLInterface* interface = SkNEW(GrGLInterface);
         glInterface.reset(interface);
         interface->fBindingsExported = kDesktop_GrGLBinding;
         interface->fActiveTexture = nullGLActiveTexture;
index 9c6743a..16a5015 100644 (file)
@@ -31,9 +31,10 @@ void GrGLTexture::init(GrGpuGL* gpu,
 
     fTexParams.invalidate();
     fTexParamsTimestamp = GrGpu::kExpiredTimestamp;
-    fTexIDObj           = new GrGLTexID(GPUGL->glInterface(),
-                                        textureDesc.fTextureID,
-                                        textureDesc.fOwnsID);
+    fTexIDObj           = SkNEW_ARGS(GrGLTexID,
+                                     (GPUGL->glInterface(),
+                                      textureDesc.fTextureID,
+                                      textureDesc.fOwnsID));
     fOrientation        = textureDesc.fOrientation;
 
     if (NULL != rtDesc) {
@@ -44,7 +45,8 @@ void GrGLTexture::init(GrGpuGL* gpu,
         vp.fBottom = 0;
         vp.fHeight = textureDesc.fHeight;
 
-        fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this);
+        fRenderTarget = SkNEW_ARGS(GrGLRenderTarget,
+                                   (gpu, *rtDesc, vp, fTexIDObj, this));
     }
 }
 
index 5baca24..0e2036c 100644 (file)
@@ -176,7 +176,7 @@ GrGpuGL::GrGpuGL(const GrGLContextInfo& ctxInfo) : fGLContextInfo(ctxInfo) {
     this->initCaps();
 
     fProgramData = NULL;
-    fProgramCache = new ProgramCache(this->glContextInfo());
+    fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContextInfo()));
 
     fLastSuccessfulStencilFmtIdx = 0;
     fCanPreserveUnpremulRoundtrip = kUnknown_CanPreserveUnpremulRoundtrip;
@@ -592,9 +592,9 @@ GrTexture* GrGpuGL::onCreatePlatformTexture(const GrPlatformTextureDesc& desc) {
                                              &glRTDesc)) {
             return NULL;
         }
-        texture = new GrGLTexture(this, glTexDesc, glRTDesc);
+        texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
     } else {
-        texture = new GrGLTexture(this, glTexDesc);
+        texture = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
     }
     if (NULL == texture) {
         return NULL;
@@ -618,19 +618,21 @@ GrRenderTarget* GrGpuGL::onCreatePlatformRenderTarget(const GrPlatformRenderTarg
     viewport.fWidth  = desc.fWidth;
     viewport.fHeight = desc.fHeight;
     
-    GrRenderTarget* tgt = new GrGLRenderTarget(this, glDesc, viewport);
+    GrRenderTarget* tgt = SkNEW_ARGS(GrGLRenderTarget,
+                                     (this, glDesc, viewport));
     if (desc.fStencilBits) {
         GrGLStencilBuffer::Format format;
         format.fInternalFormat = GrGLStencilBuffer::kUnknownInternalFormat;
         format.fPacked = false;
         format.fStencilBits = desc.fStencilBits;
         format.fTotalBits = desc.fStencilBits;
-        GrGLStencilBuffer* sb = new GrGLStencilBuffer(this,
-                                                      0,
-                                                      desc.fWidth,
-                                                      desc.fHeight,
-                                                      desc.fSampleCnt,
-                                                      format);
+        GrGLStencilBuffer* sb = SkNEW_ARGS(GrGLStencilBuffer,
+                                           (this,
+                                            0,
+                                            desc.fWidth,
+                                            desc.fHeight,
+                                            desc.fSampleCnt,
+                                            format));
         tgt->setStencilBuffer(sb);
         sb->unref();
     }
@@ -1106,9 +1108,9 @@ GrTexture* GrGpuGL::onCreateTexture(const GrTextureDesc& desc,
             GL_CALL(DeleteTextures(1, &glTexDesc.fTextureID));
             return return_null_texture();
         }
-        tex = new GrGLTexture(this, glTexDesc, glRTDesc);
+        tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc, glRTDesc));
     } else {
-        tex = new GrGLTexture(this, glTexDesc);
+        tex = SkNEW_ARGS(GrGLTexture, (this, glTexDesc));
     }
     tex->setCachedTexParams(initialTexParams, this->getResetTimestamp());
 #ifdef TRACE_TEXTURE_CREATION
@@ -1193,8 +1195,9 @@ bool GrGpuGL::createStencilBufferForRenderTarget(GrRenderTarget* rt,
             // whatever sizes GL gives us. In that case we query for the size.
             GrGLStencilBuffer::Format format = sFmt;
             get_stencil_rb_sizes(this->glInterface(), sbID, &format);
-            sb = new GrGLStencilBuffer(this, sbID, width, height, 
-                                       samples, format);
+            sb = SkNEW_ARGS(GrGLStencilBuffer,
+                            (this, sbID, width, height, 
+                             samples, format));
             if (this->attachStencilBufferToRenderTarget(sb, rt)) {
                 fLastSuccessfulStencilFmtIdx = sIdx;
                 rt->setStencilBuffer(sb);
@@ -1295,8 +1298,9 @@ GrVertexBuffer* GrGpuGL::onCreateVertexBuffer(uint32_t size, bool dynamic) {
             fHWGeometryState.fVertexBuffer = NULL;
             return NULL;
         }
-        GrGLVertexBuffer* vertexBuffer = new GrGLVertexBuffer(this, id,
-                                                              size, dynamic);
+        GrGLVertexBuffer* vertexBuffer = SkNEW_ARGS(GrGLVertexBuffer,
+                                                    (this, id,
+                                                     size, dynamic));
         fHWGeometryState.fVertexBuffer = vertexBuffer;
         return vertexBuffer;
     }
@@ -1322,8 +1326,8 @@ GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) {
             fHWGeometryState.fIndexBuffer = NULL;
             return NULL;
         }
-        GrIndexBuffer* indexBuffer = new GrGLIndexBuffer(this, id,
-                                                         size, dynamic);
+        GrIndexBuffer* indexBuffer = SkNEW_ARGS(GrGLIndexBuffer,
+                                                (this, id, size, dynamic));
         fHWGeometryState.fIndexBuffer = indexBuffer;
         return indexBuffer;
     }
@@ -1332,7 +1336,7 @@ GrIndexBuffer* GrGpuGL::onCreateIndexBuffer(uint32_t size, bool dynamic) {
 
 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) {
     GrAssert(fCaps.fPathStencilingSupport);
-    return new GrGLPath(this, inPath);
+    return SkNEW_ARGS(GrGLPath, (this, inPath));
 }
 
 void GrGpuGL::flushScissor() {
index 5845919..7f71f48 100644 (file)
@@ -65,9 +65,10 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
             // does not work with perspective or mul-by-alpha-mask
             stageDesc->fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
             stageDesc->fInConfigFlags &= ~kMulByAlphaMask;
-            return new GrConvolutionEffect(gKernelDirections[direction],
-                                           kernelRadius,
-                                           kernel);
+            return SkNEW_ARGS(GrConvolutionEffect,
+                              (gKernelDirections[direction],
+                               kernelRadius,
+                               kernel));
             }
         case kErode_EffectType: {
             int direction = random_int(random, 2);
@@ -75,9 +76,10 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
             // does not work with perspective or mul-by-alpha-mask
             stageDesc->fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
             stageDesc->fInConfigFlags &= ~kMulByAlphaMask;
-            return new GrMorphologyEffect(gKernelDirections[direction],
-                                          kernelRadius,
-                                          GrContext::kErode_MorphologyType);
+            return SkNEW_ARGS(GrMorphologyEffect,
+                              (gKernelDirections[direction],
+                               kernelRadius,
+                               GrContext::kErode_MorphologyType));
             }
         case kDilate_EffectType: {
             int direction = random_int(random, 2);
@@ -85,12 +87,13 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
             // does not work with perspective or mul-by-alpha-mask
             stageDesc->fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
             stageDesc->fInConfigFlags &= ~kMulByAlphaMask;
-            return new GrMorphologyEffect(gKernelDirections[direction],
-                                          kernelRadius,
-                                          GrContext::kDilate_MorphologyType);
+            return SkNEW_ARGS(GrMorphologyEffect,
+                              (gKernelDirections[direction],
+                               kernelRadius,
+                               GrContext::kDilate_MorphologyType));
             }
         case kRadialGradient_EffectType: {
-            return new GrRadialGradient();
+            return SkNEW(GrRadialGradient);
             }
         case kRadial2Gradient_EffectType: {
             float center;
@@ -99,10 +102,10 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
             } while (GR_Scalar1 == center);
             float radius = random->nextF();
             bool root = random_bool(random);
-            return new GrRadial2Gradient(center, radius, root);
+            return SkNEW_ARGS(GrRadial2Gradient, (center, radius, root));
             }
         case kSweepGradient_EffectType: {
-            return new GrSweepGradient();
+            return SkNEW(GrSweepGradient);
             }
         default:
             GrCrash("Unexpected custom effect type");
index b19f9b4..e9e8f8d 100644 (file)
@@ -17,7 +17,7 @@ extern "C" {
 void gr_hello_world() {
     static GrGpu* gGpu;
     if (NULL == gGpu) {
-        gGpu = new SkGpuGLShaders;
+        gGpu = SkNEW(SkGpuGLShaders);
     }
 
     SkGLCanvas canvas(gGpu);