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

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

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 #ifndef SkPDFCanon_DEFINED 7 #ifndef SkPDFCanon_DEFINED
8 #define SkPDFCanon_DEFINED 8 #define SkPDFCanon_DEFINED
9 9
10 #include "SkPDFGraphicState.h"
10 #include "SkPDFShader.h" 11 #include "SkPDFShader.h"
11 #include "SkTDArray.h" 12 #include "SkTDArray.h"
13 #include "SkTHash.h"
12 14
13 class SkBitmap; 15 class SkBitmap;
14 class SkPDFFont; 16 class SkPDFFont;
15 class SkPDFGraphicState;
16 class SkPDFBitmap; 17 class SkPDFBitmap;
17 class SkPaint; 18 class SkPaint;
18 19
19 /** 20 /**
20 * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices). 21 * The SkPDFCanon canonicalizes objects across PDF pages(SkPDFDevices).
21 * 22 *
22 * The PDF backend works correctly if: 23 * The PDF backend works correctly if:
23 * - There is no more than one SkPDFCanon for each thread. 24 * - There is no more than one SkPDFCanon for each thread.
24 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation. 25 * - Every SkPDFDevice is given a pointer to a SkPDFCanon on creation.
25 * - All SkPDFDevices in a document share the same SkPDFCanon. 26 * - All SkPDFDevices in a document share the same SkPDFCanon.
(...skipping 23 matching lines...) Expand all
49 50
50 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const; 51 SkPDFFunctionShader* findFunctionShader(const SkPDFShader::State&) const;
51 void addFunctionShader(SkPDFFunctionShader*); 52 void addFunctionShader(SkPDFFunctionShader*);
52 53
53 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const; 54 SkPDFAlphaFunctionShader* findAlphaShader(const SkPDFShader::State&) const;
54 void addAlphaShader(SkPDFAlphaFunctionShader*); 55 void addAlphaShader(SkPDFAlphaFunctionShader*);
55 56
56 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const; 57 SkPDFImageShader* findImageShader(const SkPDFShader::State&) const;
57 void addImageShader(SkPDFImageShader*); 58 void addImageShader(SkPDFImageShader*);
58 59
59 SkPDFGraphicState* findGraphicState(const SkPaint&) const; 60 SkPDFGraphicState* findGraphicState(SkPDFGraphicState&) const;
mtklein 2015/04/01 20:05:39 It's unusual for us to have non-const refs as func
60 void addGraphicState(SkPDFGraphicState*); 61 void addGraphicState(SkPDFGraphicState*);
61 62
62 SkPDFBitmap* findBitmap(const SkBitmap&) const; 63 SkPDFBitmap* findBitmap(const SkBitmap&) const;
63 void addBitmap(SkPDFBitmap*); 64 void addBitmap(SkPDFBitmap*);
64 65
65 private: 66 private:
66 struct FontRec { 67 struct FontRec {
67 SkPDFFont* fFont; 68 SkPDFFont* fFont;
68 uint32_t fFontID; 69 uint32_t fFontID;
69 uint16_t fGlyphID; 70 uint16_t fGlyphID;
70 }; 71 };
71 SkTDArray<FontRec> fFontRecords; 72 SkTDArray<FontRec> fFontRecords;
72 73
73 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords; 74 SkTDArray<SkPDFFunctionShader*> fFunctionShaderRecords;
74 75
75 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords; 76 SkTDArray<SkPDFAlphaFunctionShader*> fAlphaShaderRecords;
76 77
77 SkTDArray<SkPDFImageShader*> fImageShaderRecords; 78 SkTDArray<SkPDFImageShader*> fImageShaderRecords;
78 79
79 SkTDArray<SkPDFGraphicState*> fGraphicStateRecords; 80 template <typename T>
mtklein 2015/04/01 20:05:39 This doesn't really need to be templated, does it?
81 struct Wrap {
mtklein 2015/04/01 20:05:39 // Wrap lets us store pointers in the hash set, bu
82 explicit Wrap(T* ptr = NULL) : fPtr(ptr) {}
mtklein 2015/04/01 20:05:39 Do we do anything with these pointers that isn't c
83 T* fPtr;
84 bool operator==(const Wrap<T>& rhs) const {
85 SkASSERT(fPtr);
86 SkASSERT(rhs.fPtr);
87 return *fPtr == *rhs.fPtr;
88 }
89 static uint32_t Hash(const Wrap<T>& w) {
90 SkASSERT(w.fPtr);
91 return SkGoodHash(w.fPtr->hash());
mtklein 2015/04/01 20:05:39 Seems like overkill to rehash a hash?
92 }
93 };
94 SkTHashSet<Wrap<SkPDFGraphicState>, Wrap<SkPDFGraphicState>::Hash>
95 fGraphicStateRecords;
80 96
81 SkTDArray<SkPDFBitmap*> fBitmapRecords; 97 SkTDArray<SkPDFBitmap*> fBitmapRecords;
82 }; 98 };
83 #endif // SkPDFCanon_DEFINED 99 #endif // SkPDFCanon_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkTHash.h ('k') | src/pdf/SkPDFCanon.cpp » ('j') | src/pdf/SkPDFCanon.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698