Home | History | Annotate | Download | only in core
      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 "SkImage.h"
     10 #include <algorithm>
     11 
     12 SkRecord::~SkRecord() {
     13     Destroyer destroyer;
     14     for (int i = 0; i < this->count(); i++) {
     15         this->mutate(i, destroyer);
     16     }
     17 }
     18 
     19 void SkRecord::grow() {
     20     SkASSERT(fCount == fReserved);
     21     fReserved = fReserved ? fReserved * 2 : 4;
     22     fRecords.realloc(fReserved);
     23 }
     24 
     25 size_t SkRecord::bytesUsed() const {
     26     size_t bytes = fApproxBytesAllocated + sizeof(SkRecord);
     27     return bytes;
     28 }
     29 
     30 void SkRecord::defrag() {
     31     // Remove all the NoOps, preserving the order of other ops, e.g.
     32     //      Save, ClipRect, NoOp, DrawRect, NoOp, NoOp, Restore
     33     //  ->  Save, ClipRect, DrawRect, Restore
     34     Record* noops = std::remove_if(fRecords.get(), fRecords.get() + fCount,
     35                                    [](Record op) { return op.type() == SkRecords::NoOp_Type; });
     36     fCount = noops - fRecords.get();
     37 }
     38