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