Add placement new macros to SkPostConfig, call SkNEW* from Ganesh.

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
diff --git a/src/gpu/gl/GrGLCreateNullInterface.cpp b/src/gpu/gl/GrGLCreateNullInterface.cpp
index b9a3c5e..6451fca 100644
--- a/src/gpu/gl/GrGLCreateNullInterface.cpp
+++ b/src/gpu/gl/GrGLCreateNullInterface.cpp
@@ -388,7 +388,7 @@
     // 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;
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index 9c6743a..16a5015 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -31,9 +31,10 @@
 
     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 @@
         vp.fBottom = 0;
         vp.fHeight = textureDesc.fHeight;
 
-        fRenderTarget = new GrGLRenderTarget(gpu, *rtDesc, vp, fTexIDObj, this);
+        fRenderTarget = SkNEW_ARGS(GrGLRenderTarget,
+                                   (gpu, *rtDesc, vp, fTexIDObj, this));
     }
 }
 
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 5baca24..0e2036c 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -176,7 +176,7 @@
     this->initCaps();
 
     fProgramData = NULL;
-    fProgramCache = new ProgramCache(this->glContextInfo());
+    fProgramCache = SkNEW_ARGS(ProgramCache, (this->glContextInfo()));
 
     fLastSuccessfulStencilFmtIdx = 0;
     fCanPreserveUnpremulRoundtrip = kUnknown_CanPreserveUnpremulRoundtrip;
@@ -592,9 +592,9 @@
                                              &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 @@
     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 @@
             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 @@
             // 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 @@
             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 @@
             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 @@
 
 GrPath* GrGpuGL::onCreatePath(const SkPath& inPath) {
     GrAssert(fCaps.fPathStencilingSupport);
-    return new GrGLPath(this, inPath);
+    return SkNEW_ARGS(GrGLPath, (this, inPath));
 }
 
 void GrGpuGL::flushScissor() {
diff --git a/src/gpu/gl/GrGpuGL_unittest.cpp b/src/gpu/gl/GrGpuGL_unittest.cpp
index 5845919..7f71f48 100644
--- a/src/gpu/gl/GrGpuGL_unittest.cpp
+++ b/src/gpu/gl/GrGpuGL_unittest.cpp
@@ -65,9 +65,10 @@
             // 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 @@
             // 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 @@
             // 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 @@
             } 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");