blob: 5e8a2cb0c23c33d33e3c296fb83cb8b0fc551b55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkImage.h"
#include "SkPDFBitmap.h"
#include "SkPDFCanon.h"
#include "SkPDFFont.h"
////////////////////////////////////////////////////////////////////////////////
SkPDFCanon::~SkPDFCanon() {
fGraphicStateRecords.foreach ([](WrapGS w) { w.fPtr->unref(); });
}
////////////////////////////////////////////////////////////////////////////////
template <typename T>
sk_sp<SkPDFObject> find_shader(const SkTArray<T>& records,
const SkPDFShader::State& state) {
for (const T& record : records) {
if (record.fShaderState == state) {
return record.fShaderObject;
}
}
return nullptr;
}
sk_sp<SkPDFObject> SkPDFCanon::findFunctionShader(
const SkPDFShader::State& state) const {
return find_shader(fFunctionShaderRecords, state);
}
void SkPDFCanon::addFunctionShader(sk_sp<SkPDFObject> pdfShader,
SkPDFShader::State state) {
fFunctionShaderRecords.emplace_back(ShaderRec{std::move(state), std::move(pdfShader)});
}
sk_sp<SkPDFObject> SkPDFCanon::findAlphaShader(
const SkPDFShader::State& state) const {
return find_shader(fAlphaShaderRecords, state);
}
void SkPDFCanon::addAlphaShader(sk_sp<SkPDFObject> pdfShader,
SkPDFShader::State state) {
fAlphaShaderRecords.emplace_back(ShaderRec{std::move(state), std::move(pdfShader)});
}
sk_sp<SkPDFObject> SkPDFCanon::findImageShader(
const SkPDFShader::State& state) const {
return find_shader(fImageShaderRecords, state);
}
void SkPDFCanon::addImageShader(sk_sp<SkPDFObject> pdfShader,
SkPDFShader::State state) {
fImageShaderRecords.emplace_back(ShaderRec{std::move(state), std::move(pdfShader)});
}
////////////////////////////////////////////////////////////////////////////////
const SkPDFGraphicState* SkPDFCanon::findGraphicState(
const SkPDFGraphicState& key) const {
const WrapGS* ptr = fGraphicStateRecords.find(WrapGS(&key));
return ptr ? ptr->fPtr : nullptr;
}
void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) {
SkASSERT(state);
WrapGS w(SkRef(state));
SkASSERT(!fGraphicStateRecords.contains(w));
fGraphicStateRecords.add(w);
}
|