SkRecord.cpp 1.0 KB

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