Add a class to allocate small objects w/o extra calls to new.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 7 Mar 2014 03:24:41 +0000 (03:24 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 7 Mar 2014 03:24:41 +0000 (03:24 +0000)
commita5572e5bb2a2bbeeb59de0741c2527869d365a0c
treedcc5ca5a5f15d9cb45e7b4a4681900fb9c41a90d
parent1d328e46179b12149aec48ccdcf39bd853bb3ec5
Add a class to allocate small objects w/o extra calls to new.

Add SkSmallAllocator, a template for allocating small (as defined by the
instantiation) objects without extra calls to new. Add a helper macro to
make using it simple.

Remove SkTemplatesPriv.h, whose behavior is replaced by SkSmallAllocator.
The old SK_PLACEMENT_NEW had the following drawbacks:
- Easily confused with SkNEW_PLACEMENT.
- Requires passing around lots of void*s along with the storageSize.
- Requires using a separate class for deleting it.
- We had multiple ways Auto objects for deleting in different places.
- It always did a straight heap allocation on Windows, meaning Windows
  did not get any advantages from the confusing code.
The new SkSmallAllocator simplifies things:
- It is clear about what it does.
- It takes care of the deletion in one place that is automatically
  handled.

Further, the new class can be used to create more than one object. This
is in preparation for BUG=skia:1976, for which we would like to create
a new object without extra heap allocations. The plan is to create both
the blitter and the new object on the stack using the SkSmallAllocator.

Add a new test for SkSmallAllocator.

SkShader.h:
Move the private version of CreateBitmapShader to SkBitmapProcShader
(which already has the implementation) and remove the friend class
(which was only used to call this private function). This allows
SkSmallAllocator to reside in the private src/ directory.

SkBitmapProcShader:
Move CreateBitmapShader and the macro for the storage size here. With
the macro in a (private) header, the (private) headers with function
declarations (which now depend on the storage size used) can see the
macro.
Use SkSmallAllocator in CreateBitmapShader.
Change the macro to kBlitterStorageByteCount, since SkSmallAllocator
takes a byte count as its template parameter.

SkBlitter:
Use the SkSmallAllocator.
Remove Sk3DShader::fKillProc and SkAutoCallProc. Both of their
behaviors have been moved into SkSmallAllocator (SkAutoCallProc was
unnecessary anyway, because the only time we ever used it we also
called detach(), so its auto behavior never happened).
Create the Sk3DShader on the stack, if there's room.
Remove the helper version of Choose, which was unused.

SmallAllocatorTest:
Test for the new class.

The rest:
Use SkSmallAllocator.

BUG=skia:1976
R=reed@google.com, mtklein@google.com

Author: scroggo@google.com

Review URL: https://codereview.chromium.org/179343005

git-svn-id: http://skia.googlecode.com/svn/trunk@13696 2bbb7eff-a529-9590-31e7-b0007b416f81
18 files changed:
gyp/core.gypi
gyp/tests.gypi
include/core/SkShader.h
src/core/SkBitmapProcShader.cpp
src/core/SkBitmapProcShader.h
src/core/SkBlitter.cpp
src/core/SkBlitter.h
src/core/SkBlitter_RGB16.cpp
src/core/SkBlitter_Sprite.cpp
src/core/SkCoreBlitters.h
src/core/SkDraw.cpp
src/core/SkShader.cpp
src/core/SkSmallAllocator.h [new file with mode: 0644]
src/core/SkSpriteBlitter.h
src/core/SkSpriteBlitter_ARGB32.cpp
src/core/SkSpriteBlitter_RGB16.cpp
src/core/SkTemplatesPriv.h [deleted file]
tests/SmallAllocatorTest.cpp [new file with mode: 0644]