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

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

Issue 1046293002: SkPDF: SkPDFGraphicState Lookup hashtabled (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-04-01 (Wednesday) 15:28:18 EDT Created 5 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPDFBitmap.h" 8 #include "SkPDFBitmap.h"
9 #include "SkPDFCanon.h" 9 #include "SkPDFCanon.h"
10 #include "SkPDFFont.h" 10 #include "SkPDFFont.h"
11 #include "SkPDFGraphicState.h"
12 #include "SkPDFShader.h" 11 #include "SkPDFShader.h"
13 12
14 //////////////////////////////////////////////////////////////////////////////// 13 ////////////////////////////////////////////////////////////////////////////////
15 14
16 void SkPDFCanon::reset() { 15 void SkPDFCanon::reset() {
17 for (int i = 0; i < fFontRecords.count(); ++i) { 16 for (int i = 0; i < fFontRecords.count(); ++i) {
18 fFontRecords[i].fFont->unref(); 17 fFontRecords[i].fFont->unref();
19 } 18 }
20 fFontRecords.reset(); 19 fFontRecords.reset();
21 fFunctionShaderRecords.unrefAll(); 20 fFunctionShaderRecords.unrefAll();
22 fFunctionShaderRecords.reset(); 21 fFunctionShaderRecords.reset();
23 fAlphaShaderRecords.unrefAll(); 22 fAlphaShaderRecords.unrefAll();
24 fAlphaShaderRecords.reset(); 23 fAlphaShaderRecords.reset();
25 fImageShaderRecords.unrefAll(); 24 fImageShaderRecords.unrefAll();
26 fImageShaderRecords.reset(); 25 fImageShaderRecords.reset();
27 fGraphicStateRecords.unrefAll(); 26 fGraphicStateRecords.foreach (
27 [](Wrap<SkPDFGraphicState> ptr) { ptr.fPtr->unref(); });
28 fGraphicStateRecords.reset(); 28 fGraphicStateRecords.reset();
29 fBitmapRecords.unrefAll(); 29 fBitmapRecords.unrefAll();
30 fBitmapRecords.reset(); 30 fBitmapRecords.reset();
31 } 31 }
32 32
33 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
34 34
35 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } 35 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; }
36 36
37 // requires `bool T::equals(const U&) const` 37 // requires `bool T::equals(const U&) const`
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 const SkPDFShader::State& state) const { 100 const SkPDFShader::State& state) const {
101 return find_item(fImageShaderRecords, state); 101 return find_item(fImageShaderRecords, state);
102 } 102 }
103 103
104 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) { 104 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) {
105 fImageShaderRecords.push(SkRef(pdfShader)); 105 fImageShaderRecords.push(SkRef(pdfShader));
106 } 106 }
107 107
108 //////////////////////////////////////////////////////////////////////////////// 108 ////////////////////////////////////////////////////////////////////////////////
109 109
110 SkPDFGraphicState* SkPDFCanon::findGraphicState(const SkPaint& paint) const { 110 SkPDFGraphicState* SkPDFCanon::findGraphicState(SkPDFGraphicState& key) const {
111 return find_item(fGraphicStateRecords, paint); 111 const Wrap<SkPDFGraphicState>* ptr =
112 fGraphicStateRecords.find(Wrap<SkPDFGraphicState>(&key));
113 return ptr ? ptr->fPtr : NULL;
mtklein 2015/04/01 20:05:39 It does not seem safe to return a non-const pointe
112 } 114 }
113 115
114 void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) { 116 void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) {
115 fGraphicStateRecords.push(SkRef(state)); 117 SkASSERT(state);
118 Wrap<SkPDFGraphicState> w(SkRef(state));
119 SkASSERT(!fGraphicStateRecords.contains(w));
120 fGraphicStateRecords.add(w);
116 } 121 }
117 122
118 //////////////////////////////////////////////////////////////////////////////// 123 ////////////////////////////////////////////////////////////////////////////////
119 124
120 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const { 125 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const {
121 return find_item(fBitmapRecords, bm); 126 return find_item(fBitmapRecords, bm);
122 } 127 }
123 128
124 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) { 129 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) {
125 fBitmapRecords.push(SkRef(pdfBitmap)); 130 fBitmapRecords.push(SkRef(pdfBitmap));
126 } 131 }
OLDNEW
« src/pdf/SkPDFCanon.h ('K') | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698