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

Issue 179343005: Add a class to allocate small objects w/o extra calls to new. (Closed)

Created:
6 years, 9 months ago by scroggo
Modified:
6 years, 9 months ago
Reviewers:
mtklein, reed1
CC:
skia-review_googlegroups.com, tfarina
Base URL:
https://skia.googlesource.com/skia.git@master
Visibility:
Public.

Description

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 Committed: http://code.google.com/p/skia/source/detail?r=13696

Patch Set 1 #

Patch Set 2 : #

Total comments: 17

Patch Set 3 : Respond to comments. #

Patch Set 4 : Small comment fixes. #

Total comments: 17

Patch Set 5 : Respond to mtklein's comments in patch set 4. #

Patch Set 6 : Assert when using the heap. #

Patch Set 7 : Rename the .h file #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+375 lines, -290 lines) Patch
M gyp/core.gypi View 1 2 1 chunk +0 lines, -1 line 0 comments Download
M gyp/tests.gypi View 1 2 2 chunks +2 lines, -0 lines 0 comments Download
M include/core/SkShader.h View 1 chunk +0 lines, -4 lines 0 comments Download
M src/core/SkBitmapProcShader.h View 1 2 3 4 5 6 2 chunks +11 lines, -0 lines 0 comments Download
M src/core/SkBitmapProcShader.cpp View 1 2 2 chunks +17 lines, -10 lines 0 comments Download
M src/core/SkBlitter.h View 1 2 3 4 5 6 2 chunks +6 lines, -9 lines 0 comments Download
M src/core/SkBlitter.cpp View 1 2 3 4 5 6 8 chunks +28 lines, -76 lines 0 comments Download
M src/core/SkBlitter_RGB16.cpp View 1 2 3 chunks +10 lines, -15 lines 0 comments Download
M src/core/SkBlitter_Sprite.cpp View 1 2 3 4 5 6 4 chunks +6 lines, -11 lines 0 comments Download
M src/core/SkCoreBlitters.h View 1 2 3 4 5 6 2 chunks +5 lines, -3 lines 0 comments Download
M src/core/SkDraw.cpp View 1 2 3 4 5 6 7 chunks +25 lines, -40 lines 0 comments Download
M src/core/SkShader.cpp View 2 chunks +5 lines, -5 lines 0 comments Download
A src/core/SkSmallAllocator.h View 1 2 3 4 5 6 1 chunk +148 lines, -0 lines 1 comment Download
M src/core/SkSpriteBlitter.h View 1 2 3 4 5 6 2 chunks +6 lines, -3 lines 0 comments Download
M src/core/SkSpriteBlitter_ARGB32.cpp View 1 2 2 chunks +8 lines, -14 lines 0 comments Download
M src/core/SkSpriteBlitter_RGB16.cpp View 1 2 3 chunks +15 lines, -23 lines 0 comments Download
D src/core/SkTemplatesPriv.h View 1 chunk +0 lines, -76 lines 0 comments Download
A tests/SmallAllocatorTest.cpp View 1 2 3 4 5 6 1 chunk +83 lines, -0 lines 0 comments Download

Messages

Total messages: 17 (0 generated)
scroggo
6 years, 9 months ago (2014-02-27 17:01:11 UTC) #1
tfarina
https://codereview.chromium.org/179343005/diff/40001/tests/StackAllocatorTest.cpp File tests/StackAllocatorTest.cpp (right): https://codereview.chromium.org/179343005/diff/40001/tests/StackAllocatorTest.cpp#newcode8 tests/StackAllocatorTest.cpp:8: #include "Test.h" could you keep this sorted?
6 years, 9 months ago (2014-02-27 17:33:15 UTC) #2
bungeman-skia
https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h File src/core/SkStackAllocator.h (right): https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h#newcode81 src/core/SkStackAllocator.h:81: * this function so we can create the object ...
6 years, 9 months ago (2014-02-27 18:26:01 UTC) #3
reed1
https://codereview.chromium.org/179343005/diff/40001/src/core/SkBlitter.cpp File src/core/SkBlitter.cpp (right): https://codereview.chromium.org/179343005/diff/40001/src/core/SkBlitter.cpp#newcode815 src/core/SkBlitter.cpp:815: SkStackAllocator<kBlitterStorageByteCount>* allocator, typedef SkStackAllocator<kBlitterStorageByteCount> SkTBlitterAllocator; ?
6 years, 9 months ago (2014-02-27 18:48:12 UTC) #4
mtklein
https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h File src/core/SkStackAllocator.h (right): https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h#newcode81 src/core/SkStackAllocator.h:81: * this function so we can create the object ...
6 years, 9 months ago (2014-02-27 18:51:02 UTC) #5
mtklein
https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h File src/core/SkStackAllocator.h (right): https://codereview.chromium.org/179343005/diff/40001/src/core/SkStackAllocator.h#newcode49 src/core/SkStackAllocator.h:49: * Template class for allocating small (as defined by ...
6 years, 9 months ago (2014-02-27 23:40:54 UTC) #6
scroggo
https://codereview.chromium.org/179343005/diff/40001/src/core/SkBlitter.cpp File src/core/SkBlitter.cpp (right): https://codereview.chromium.org/179343005/diff/40001/src/core/SkBlitter.cpp#newcode815 src/core/SkBlitter.cpp:815: SkStackAllocator<kBlitterStorageByteCount>* allocator, On 2014/02/27 18:48:12, reed1 wrote: > typedef ...
6 years, 9 months ago (2014-03-05 20:25:51 UTC) #7
mtklein
lgtm with a couple new questions https://codereview.chromium.org/179343005/diff/80001/src/core/SkBitmapProcShader.cpp File src/core/SkBitmapProcShader.cpp (right): https://codereview.chromium.org/179343005/diff/80001/src/core/SkBitmapProcShader.cpp#newcode308 src/core/SkBitmapProcShader.cpp:308: SkShader::TileMode tmy, SkTBlitterAllocator* ...
6 years, 9 months ago (2014-03-05 20:59:56 UTC) #8
scroggo
https://codereview.chromium.org/179343005/diff/80001/src/core/SkBitmapProcShader.cpp File src/core/SkBitmapProcShader.cpp (right): https://codereview.chromium.org/179343005/diff/80001/src/core/SkBitmapProcShader.cpp#newcode308 src/core/SkBitmapProcShader.cpp:308: SkShader::TileMode tmy, SkTBlitterAllocator* allocator) { On 2014/03/05 20:59:56, mtklein ...
6 years, 9 months ago (2014-03-05 23:23:26 UTC) #9
mtklein
https://codereview.chromium.org/179343005/diff/80001/src/core/SkStackAllocator.h File src/core/SkStackAllocator.h (right): https://codereview.chromium.org/179343005/diff/80001/src/core/SkStackAllocator.h#newcode26 src/core/SkStackAllocator.h:26: * kBytes is the number of bytes provided for ...
6 years, 9 months ago (2014-03-06 15:04:07 UTC) #10
scroggo
ptal https://codereview.chromium.org/179343005/diff/80001/src/core/SkStackAllocator.h File src/core/SkStackAllocator.h (right): https://codereview.chromium.org/179343005/diff/80001/src/core/SkStackAllocator.h#newcode27 src/core/SkStackAllocator.h:27: * than the storage (minus storage already used), ...
6 years, 9 months ago (2014-03-06 18:07:04 UTC) #11
mtklein
> > Won't the devious SkComposeShaders overrun the hard count limit? > > That may ...
6 years, 9 months ago (2014-03-06 18:34:25 UTC) #12
scroggo
https://codereview.chromium.org/179343005/diff/170001/src/core/SkSmallAllocator.h File src/core/SkSmallAllocator.h (right): https://codereview.chromium.org/179343005/diff/170001/src/core/SkSmallAllocator.h#newcode8 src/core/SkSmallAllocator.h:8: #ifndef SkSmallAllocator_DEFINED Reitveld isn't smart enough to notice this ...
6 years, 9 months ago (2014-03-06 18:48:18 UTC) #13
reed1
public API lgtm
6 years, 9 months ago (2014-03-06 19:17:56 UTC) #14
scroggo
The CQ bit was checked by scroggo@google.com
6 years, 9 months ago (2014-03-06 19:59:09 UTC) #15
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://skia-tree-status.appspot.com/cq/scroggo@google.com/179343005/170001
6 years, 9 months ago (2014-03-06 19:59:15 UTC) #16
commit-bot: I haz the power
6 years, 9 months ago (2014-03-07 03:24:47 UTC) #17
Message was sent while issue was closed.
Change committed as 13696

Powered by Google App Engine
This is Rietveld 408576698