Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: src/pdf/SkPDFCanon.cpp

Issue 842253003: SkPDFCanon (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: did you mean struct here? Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFFont.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 "SkLazyPtr.h"
9 #include "SkPDFCanon.h"
10 #include "SkPDFFont.h"
11 #include "SkPDFGraphicState.h"
12 #include "SkPDFShader.h"
13
14 ////////////////////////////////////////////////////////////////////////////////
15
16 SK_DECLARE_STATIC_MUTEX(gSkPDFCanonFontMutex);
17 SK_DECLARE_STATIC_MUTEX(gSkPDFCanonShaderMutex);
18 SK_DECLARE_STATIC_MUTEX(gSkPDFCanonPaintMutex);
19
20 SkBaseMutex& SkPDFCanon::GetFontMutex() { return gSkPDFCanonFontMutex; }
21 SkBaseMutex& SkPDFCanon::GetShaderMutex() { return gSkPDFCanonShaderMutex; }
22 SkBaseMutex& SkPDFCanon::GetPaintMutex() { return gSkPDFCanonPaintMutex; }
23
24 SkPDFCanon::SkPDFCanon() {}
25
26 SkPDFCanon::~SkPDFCanon() {}
27
28 SK_DECLARE_STATIC_LAZY_PTR(SkPDFCanon, singleton);
29
30 SkPDFCanon& SkPDFCanon::GetCanon() { return *singleton.get(); }
31
32 ////////////////////////////////////////////////////////////////////////////////
33
34 static void assert_mutex_held(const SkPDFCanon* canon, SkBaseMutex& mutex) {
35 if (canon == singleton.get()) {
36 mutex.assertHeld();
37 }
38 }
39
40 SkPDFFont* SkPDFCanon::findFont(uint32_t fontID,
41 uint16_t glyphID,
42 SkPDFFont** relatedFontPtr) const {
43 assert_mutex_held(this, gSkPDFCanonFontMutex);
44 SkASSERT(relatedFontPtr);
45
46 SkPDFFont* relatedFont = NULL;
47 for (int i = 0; i < fFontRecords.count(); ++i) {
48 SkPDFFont::Match match = SkPDFFont::IsMatch(
49 fFontRecords[i].fFont, fFontRecords[i].fFontID,
50 fFontRecords[i].fGlyphID, fontID, glyphID);
51 if (SkPDFFont::kExact_Match == match) {
52 return fFontRecords[i].fFont;
53 } else if (!relatedFont && SkPDFFont::kRelated_Match == match) {
54 relatedFont = fFontRecords[i].fFont;
55 }
56 }
57 *relatedFontPtr = relatedFont; // May still be NULL.
58 return NULL;
59 }
60
61 void SkPDFCanon::addFont(SkPDFFont* font, uint32_t fontID, uint16_t fGlyphID) {
62 assert_mutex_held(this, gSkPDFCanonFontMutex);
63 SkPDFCanon::FontRec* rec = fFontRecords.push();
64 rec->fFont = font;
65 rec->fFontID = fontID;
66 rec->fGlyphID = fGlyphID;
67 }
68
69 void SkPDFCanon::removeFont(SkPDFFont* pdfFont) {
70 assert_mutex_held(this, gSkPDFCanonFontMutex);
71 for (int i = 0; i < fFontRecords.count(); i++) {
72 if (fFontRecords[i].fFont == pdfFont) {
73 fFontRecords.removeShuffle(i);
74 return;
75 }
76 }
77 // Not all SkPDFFonts are added to the Canon.
78 }
79
80 ////////////////////////////////////////////////////////////////////////////////
81
82 SkPDFShader* SkPDFCanon::findShader(const SkPDFShader::State& state) const {
83 assert_mutex_held(this, gSkPDFCanonShaderMutex);
84 for (int i = 0; i < fShaderRecords.count(); ++i) {
85 if (fShaderRecords[i]->equals(state)) {
86 return fShaderRecords[i];
87 }
88 }
89 return NULL;
90 }
91
92 void SkPDFCanon::addShader(SkPDFShader* shader) {
93 assert_mutex_held(this, gSkPDFCanonShaderMutex);
94 SkASSERT(shader);
95 fShaderRecords.push(shader);
96 }
97
98 void SkPDFCanon::removeShader(SkPDFShader* pdfShader) {
99 assert_mutex_held(this, gSkPDFCanonShaderMutex);
100 for (int i = 0; i < fShaderRecords.count(); ++i) {
101 if (fShaderRecords[i] == pdfShader) {
102 fShaderRecords.removeShuffle(i);
103 return;
104 }
105 }
106 SkDEBUGFAIL("pdfShader not found");
107 }
108
109 ////////////////////////////////////////////////////////////////////////////////
110
111 SkPDFGraphicState* SkPDFCanon::findGraphicState(const SkPaint& paint) const {
112 assert_mutex_held(this, gSkPDFCanonPaintMutex);
113 for (int i = 0; i < fGraphicStateRecords.count(); ++i) {
114 if (fGraphicStateRecords[i]->equals(paint)) {
115 return fGraphicStateRecords[i];
116 }
117 }
118 return NULL;
119 }
120
121 void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) {
122 assert_mutex_held(this, gSkPDFCanonPaintMutex);
123 SkASSERT(state);
124 fGraphicStateRecords.push(state);
125 }
126
127 void SkPDFCanon::removeGraphicState(SkPDFGraphicState* pdfGraphicState) {
128 assert_mutex_held(this, gSkPDFCanonPaintMutex);
129 for (int i = 0; i < fGraphicStateRecords.count(); ++i) {
130 if (fGraphicStateRecords[i] == pdfGraphicState) {
131 fGraphicStateRecords.removeShuffle(i);
132 return;
133 }
134 }
135 SkDEBUGFAIL("pdfGraphicState not found");
136 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFFont.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698