Line data Source code
1 : /*
2 : * Copyright 2015 Google Inc.
3 : *
4 : * Use of this source code is governed by a BSD-style license that can be
5 : * found in the LICENSE file.
6 : */
7 :
8 : #include "SkRecord.h"
9 : #include <algorithm>
10 :
11 0 : SkRecord::SkRecord()
12 0 : : fCount(0), fReserved(0), fAlloc(8/*first malloc at 256 bytes*/) {}
13 :
14 0 : SkRecord::~SkRecord() {
15 : Destroyer destroyer;
16 0 : for (int i = 0; i < this->count(); i++) {
17 0 : this->mutate(i, destroyer);
18 : }
19 0 : }
20 :
21 0 : void SkRecord::grow() {
22 0 : SkASSERT(fCount == fReserved);
23 0 : fReserved = fReserved ? fReserved * 2 : 4;
24 0 : fRecords.realloc(fReserved);
25 0 : }
26 :
27 0 : size_t SkRecord::bytesUsed() const {
28 : return sizeof(SkRecord)
29 0 : + fReserved * sizeof(Record)
30 0 : + fAlloc.approxBytesAllocated();
31 : }
32 :
33 0 : void SkRecord::defrag() {
34 : // Remove all the NoOps, preserving the order of other ops, e.g.
35 : // Save, ClipRect, NoOp, DrawRect, NoOp, NoOp, Restore
36 : // -> Save, ClipRect, DrawRect, Restore
37 0 : Record* noops = std::remove_if(fRecords.get(), fRecords.get() + fCount,
38 0 : [](Record op) { return op.type() == SkRecords::NoOp_Type; });
39 0 : fCount = noops - fRecords.get();
40 0 : }
|