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

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) 16:16:21 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
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ([](WrapGS w) { w.fPtr->unref(); });
28 fGraphicStateRecords.reset(); 27 fGraphicStateRecords.reset();
29 fBitmapRecords.unrefAll(); 28 fBitmapRecords.unrefAll();
30 fBitmapRecords.reset(); 29 fBitmapRecords.reset();
31 } 30 }
32 31
33 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
34 33
35 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; } 34 template <class T> T* assert_ptr(T* p) { SkASSERT(p); return p; }
36 35
37 // requires `bool T::equals(const U&) const` 36 // 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 { 99 const SkPDFShader::State& state) const {
101 return find_item(fImageShaderRecords, state); 100 return find_item(fImageShaderRecords, state);
102 } 101 }
103 102
104 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) { 103 void SkPDFCanon::addImageShader(SkPDFImageShader* pdfShader) {
105 fImageShaderRecords.push(SkRef(pdfShader)); 104 fImageShaderRecords.push(SkRef(pdfShader));
106 } 105 }
107 106
108 //////////////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////////////////
109 108
110 SkPDFGraphicState* SkPDFCanon::findGraphicState(const SkPaint& paint) const { 109 const SkPDFGraphicState* SkPDFCanon::findGraphicState(
111 return find_item(fGraphicStateRecords, paint); 110 const SkPDFGraphicState& key) const {
111 const WrapGS* ptr = fGraphicStateRecords.find(WrapGS(&key));
112 return ptr ? ptr->fPtr : NULL;
112 } 113 }
113 114
114 void SkPDFCanon::addGraphicState(SkPDFGraphicState* state) { 115 void SkPDFCanon::addGraphicState(const SkPDFGraphicState* state) {
115 fGraphicStateRecords.push(SkRef(state)); 116 SkASSERT(state);
117 WrapGS w(SkRef(state));
118 SkASSERT(!fGraphicStateRecords.contains(w));
119 fGraphicStateRecords.add(w);
116 } 120 }
117 121
118 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
119 123
120 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const { 124 SkPDFBitmap* SkPDFCanon::findBitmap(const SkBitmap& bm) const {
121 return find_item(fBitmapRecords, bm); 125 return find_item(fBitmapRecords, bm);
122 } 126 }
123 127
124 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) { 128 void SkPDFCanon::addBitmap(SkPDFBitmap* pdfBitmap) {
125 fBitmapRecords.push(SkRef(pdfBitmap)); 129 fBitmapRecords.push(SkRef(pdfBitmap));
126 } 130 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFCanon.h ('k') | src/pdf/SkPDFDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698