blob: 2895978442b6045ce06269e951f1ffd0dab4b22a [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
reed@android.com8a1c16f2008-12-17 15:59:43 +00007
Mike Reed8ad91a92018-01-19 19:09:32 -05008#include "SkPictureFlat.h"
junov@chromium.orgef760602012-06-27 20:03:16 +00009#include "SkChecksum.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000010#include "SkColorFilter.h"
11#include "SkDrawLooper.h"
12#include "SkMaskFilter.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000013#include "SkShader.h"
14#include "SkTypeface.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000015
reed@android.com8a1c16f2008-12-17 15:59:43 +000016///////////////////////////////////////////////////////////////////////////////
17
halcanary96fcdcc2015-08-27 07:41:13 -070018SkTypefacePlayback::SkTypefacePlayback() : fCount(0), fArray(nullptr) {}
reed@android.com8a1c16f2008-12-17 15:59:43 +000019
djsollen@google.com21830d92012-08-07 19:49:41 +000020SkTypefacePlayback::~SkTypefacePlayback() {
halcanary96fcdcc2015-08-27 07:41:13 -070021 this->reset(nullptr);
reed@android.com8a1c16f2008-12-17 15:59:43 +000022}
23
djsollen@google.com21830d92012-08-07 19:49:41 +000024void SkTypefacePlayback::reset(const SkRefCntSet* rec) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000025 for (int i = 0; i < fCount; i++) {
26 SkASSERT(fArray[i]);
27 fArray[i]->unref();
28 }
halcanary385fe4d2015-08-26 13:07:48 -070029 delete[] fArray;
rmistry@google.comfbfcd562012-08-23 18:09:54 +000030
halcanary96fcdcc2015-08-27 07:41:13 -070031 if (rec!= nullptr && rec->count() > 0) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000032 fCount = rec->count();
halcanary385fe4d2015-08-26 13:07:48 -070033 fArray = new SkRefCnt* [fCount];
mike@reedtribe.orge9e08cc2011-04-29 01:44:52 +000034 rec->copyToArray(fArray);
reed@android.com8a1c16f2008-12-17 15:59:43 +000035 for (int i = 0; i < fCount; i++) {
36 fArray[i]->ref();
37 }
38 } else {
39 fCount = 0;
halcanary96fcdcc2015-08-27 07:41:13 -070040 fArray = nullptr;
reed@android.com8a1c16f2008-12-17 15:59:43 +000041 }
42}
43
djsollen@google.com21830d92012-08-07 19:49:41 +000044void SkTypefacePlayback::setCount(int count) {
halcanary96fcdcc2015-08-27 07:41:13 -070045 this->reset(nullptr);
rmistry@google.comfbfcd562012-08-23 18:09:54 +000046
reed@android.com8a1c16f2008-12-17 15:59:43 +000047 fCount = count;
halcanary385fe4d2015-08-26 13:07:48 -070048 fArray = new SkRefCnt* [count];
reed@android.com4516f472009-06-29 16:25:36 +000049 sk_bzero(fArray, count * sizeof(SkRefCnt*));
reed@android.com8a1c16f2008-12-17 15:59:43 +000050}
51
djsollen@google.com21830d92012-08-07 19:49:41 +000052SkRefCnt* SkTypefacePlayback::set(int index, SkRefCnt* obj) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000053 SkASSERT((unsigned)index < (unsigned)fCount);
54 SkRefCnt_SafeAssign(fArray[index], obj);
55 return obj;
56}