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

Side by Side Diff: src/core/SkRecorder.cpp

Issue 741793002: Add SkNVRefCnt, prune down SkPicture's size (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweak name Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkRecord.h ('k') | src/core/SkVarAlloc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkData.h" 8 #include "SkData.h"
9 #include "SkRecorder.h" 9 #include "SkRecorder.h"
10 #include "SkPatchUtils.h" 10 #include "SkPatchUtils.h"
(...skipping 13 matching lines...) Expand all
24 fDrawableList.unrefAll(); 24 fDrawableList.unrefAll();
25 } 25 }
26 26
27 void SkRecorder::forgetRecord() { 27 void SkRecorder::forgetRecord() {
28 fDrawableList.unrefAll(); 28 fDrawableList.unrefAll();
29 fDrawableList.reset(); 29 fDrawableList.reset();
30 fRecord = NULL; 30 fRecord = NULL;
31 } 31 }
32 32
33 // ReleaseProc for SkData, assuming the data was allocated via sk_malloc, and it s contents are an 33 // ReleaseProc for SkData, assuming the data was allocated via sk_malloc, and it s contents are an
34 // array of SkRefCnt* which need to be unref'd. 34 // array of SkPicture* which need to be unref'd.
35 // 35 //
36 static void unref_all_malloc_releaseProc(const void* ptr, size_t length, void* c ontext) { 36 static void unref_all_malloc_releaseProc(const void* ptr, size_t length, void* c ontext) {
37 SkASSERT(ptr == context); // our context is our ptr, allocated via sk_mall oc 37 SkASSERT(ptr == context); // our context is our ptr, allocated via sk_mall oc
38 int count = SkToInt(length / sizeof(SkRefCnt*)); 38 int count = SkToInt(length / sizeof(SkPicture*));
39 SkASSERT(count * sizeof(SkRefCnt*) == length); // our length is snug for th e array 39 SkASSERT(count * sizeof(SkPicture*) == length); // our length is snug for t he array
40 40
41 SkRefCnt* const* array = reinterpret_cast<SkRefCnt* const*>(ptr); 41 SkPicture* const* array = reinterpret_cast<SkPicture* const*>(ptr);
42 for (int i = 0; i < count; ++i) { 42 for (int i = 0; i < count; ++i) {
43 SkSafeUnref(array[i]); 43 SkSafeUnref(array[i]);
44 } 44 }
45 sk_free(context); 45 sk_free(context);
46 } 46 }
47 47
48 // Return an uninitialized SkData sized for "count" SkRefCnt pointers. They will be unref'd when 48 // Return an uninitialized SkData sized for "count" SkPicture pointers. They wil l be unref'd when
49 // the SkData is destroyed. 49 // the SkData is destroyed.
50 // 50 //
51 static SkData* new_uninitialized_refcnt_ptrs(int count) { 51 static SkData* new_uninitialized_picture_ptrs(int count) {
52 size_t length = count * sizeof(SkRefCnt*); 52 size_t length = count * sizeof(SkPicture*);
53 void* array = sk_malloc_throw(length); 53 void* array = sk_malloc_throw(length);
54 void* context = array; 54 void* context = array;
55 return SkData::NewWithProc(array, length, unref_all_malloc_releaseProc, cont ext); 55 return SkData::NewWithProc(array, length, unref_all_malloc_releaseProc, cont ext);
56 } 56 }
57 57
58 SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFl ags) { 58 SkData* SkRecorder::newDrawableSnapshot(SkBBHFactory* factory, uint32_t recordFl ags) {
59 const int count = fDrawableList.count(); 59 const int count = fDrawableList.count();
60 if (0 == count) { 60 if (0 == count) {
61 return NULL; 61 return NULL;
62 } 62 }
63 SkData* data = new_uninitialized_refcnt_ptrs(count); 63 SkData* data = new_uninitialized_picture_ptrs(count);
64 SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data()); 64 SkPicture** pics = reinterpret_cast<SkPicture**>(data->writable_data());
65 for (int i = 0; i < count; ++i) { 65 for (int i = 0; i < count; ++i) {
66 pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags); 66 pics[i] = fDrawableList[i]->newPictureSnapshot(factory, recordFlags);
67 } 67 }
68 return data; 68 return data;
69 } 69 }
70 70
71 // To make appending to fRecord a little less verbose. 71 // To make appending to fRecord a little less verbose.
72 #define APPEND(T, ...) \ 72 #define APPEND(T, ...) \
73 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__)) 73 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__))
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 APPEND(EndCommentGroup); 371 APPEND(EndCommentGroup);
372 } 372 }
373 373
374 bool SkRecorder::isDrawingToLayer() const { 374 bool SkRecorder::isDrawingToLayer() const {
375 return fSaveLayerCount > 0; 375 return fSaveLayerCount > 0;
376 } 376 }
377 377
378 void SkRecorder::drawData(const void* data, size_t length) { 378 void SkRecorder::drawData(const void* data, size_t length) {
379 APPEND(DrawData, copy((const char*)data), length); 379 APPEND(DrawData, copy((const char*)data), length);
380 } 380 }
OLDNEW
« no previous file with comments | « src/core/SkRecord.h ('k') | src/core/SkVarAlloc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698