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

Side by Side Diff: src/core/SkScalerContext.cpp

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkScalerContext.h" 10 #include "SkScalerContext.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkDescriptor.h" 12 #include "SkDescriptor.h"
13 #include "SkDraw.h" 13 #include "SkDraw.h"
14 #include "SkFontHost.h" 14 #include "SkFontHost.h"
15 #include "SkGlyph.h" 15 #include "SkGlyph.h"
16 #include "SkMaskFilter.h" 16 #include "SkMaskFilter.h"
17 #include "SkMaskGamma.h" 17 #include "SkMaskGamma.h"
18 #include "SkOrderedReadBuffer.h" 18 #include "SkReadBuffer.h"
19 #include "SkOrderedWriteBuffer.h" 19 #include "SkWriteBuffer.h"
20 #include "SkPathEffect.h" 20 #include "SkPathEffect.h"
21 #include "SkRasterizer.h" 21 #include "SkRasterizer.h"
22 #include "SkRasterClip.h" 22 #include "SkRasterClip.h"
23 #include "SkStroke.h" 23 #include "SkStroke.h"
24 #include "SkThread.h" 24 #include "SkThread.h"
25 25
26 #ifdef SK_BUILD_FOR_ANDROID 26 #ifdef SK_BUILD_FOR_ANDROID
27 #include "SkTypeface_android.h" 27 #include "SkTypeface_android.h"
28 #endif 28 #endif
29 29
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #define DUMP_RECx 66 #define DUMP_RECx
67 #endif 67 #endif
68 68
69 static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag, 69 static SkFlattenable* load_flattenable(const SkDescriptor* desc, uint32_t tag,
70 SkFlattenable::Type ft) { 70 SkFlattenable::Type ft) {
71 SkFlattenable* obj = NULL; 71 SkFlattenable* obj = NULL;
72 uint32_t len; 72 uint32_t len;
73 const void* data = desc->findEntry(tag, &len); 73 const void* data = desc->findEntry(tag, &len);
74 74
75 if (data) { 75 if (data) {
76 SkOrderedReadBuffer buffer(data, len); 76 SkReadBuffer buffer(data, len);
77 obj = buffer.readFlattenable(ft); 77 obj = buffer.readFlattenable(ft);
78 SkASSERT(buffer.offset() == buffer.size()); 78 SkASSERT(buffer.offset() == buffer.size());
79 } 79 }
80 return obj; 80 return obj;
81 } 81 }
82 82
83 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc) 83 SkScalerContext::SkScalerContext(SkTypeface* typeface, const SkDescriptor* desc)
84 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)) ) 84 : fRec(*static_cast<const Rec*>(desc->findEntry(kRec_SkDescriptorTag, NULL)) )
85 85
86 , fBaseGlyphCount(0) 86 , fBaseGlyphCount(0)
(...skipping 24 matching lines...) Expand all
111 rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill, 111 rec->fFrameWidth, rec->fMiterLimit, rec->fHints, rec->fFrameAndFill,
112 rec->fMaskFormat, rec->fStrokeJoin); 112 rec->fMaskFormat, rec->fStrokeJoin);
113 SkDebugf(" pathEffect %x maskFilter %x\n", 113 SkDebugf(" pathEffect %x maskFilter %x\n",
114 desc->findEntry(kPathEffect_SkDescriptorTag, NULL), 114 desc->findEntry(kPathEffect_SkDescriptorTag, NULL),
115 desc->findEntry(kMaskFilter_SkDescriptorTag, NULL)); 115 desc->findEntry(kMaskFilter_SkDescriptorTag, NULL));
116 #endif 116 #endif
117 #ifdef SK_BUILD_FOR_ANDROID 117 #ifdef SK_BUILD_FOR_ANDROID
118 uint32_t len; 118 uint32_t len;
119 const void* data = desc->findEntry(kAndroidOpts_SkDescriptorTag, &len); 119 const void* data = desc->findEntry(kAndroidOpts_SkDescriptorTag, &len);
120 if (data) { 120 if (data) {
121 SkOrderedReadBuffer buffer(data, len); 121 SkReadBuffer buffer(data, len);
122 fPaintOptionsAndroid.unflatten(buffer); 122 fPaintOptionsAndroid.unflatten(buffer);
123 SkASSERT(buffer.offset() == buffer.size()); 123 SkASSERT(buffer.offset() == buffer.size());
124 } 124 }
125 #endif 125 #endif
126 } 126 }
127 127
128 SkScalerContext::~SkScalerContext() { 128 SkScalerContext::~SkScalerContext() {
129 SkDELETE(fNextContext); 129 SkDELETE(fNextContext);
130 130
131 SkSafeUnref(fPathEffect); 131 SkSafeUnref(fPathEffect);
132 SkSafeUnref(fMaskFilter); 132 SkSafeUnref(fMaskFilter);
133 SkSafeUnref(fRasterizer); 133 SkSafeUnref(fRasterizer);
134 } 134 }
135 135
136 // Return the context associated with the next logical typeface, or NULL if 136 // Return the context associated with the next logical typeface, or NULL if
137 // there are no more entries in the fallback chain. 137 // there are no more entries in the fallback chain.
138 SkScalerContext* SkScalerContext::allocNextContext() const { 138 SkScalerContext* SkScalerContext::allocNextContext() const {
139 #ifdef SK_BUILD_FOR_ANDROID 139 #ifdef SK_BUILD_FOR_ANDROID
140 SkTypeface* newFace = SkAndroidNextLogicalTypeface(fRec.fFontID, 140 SkTypeface* newFace = SkAndroidNextLogicalTypeface(fRec.fFontID,
141 fRec.fOrigFontID, 141 fRec.fOrigFontID,
142 fPaintOptionsAndroid); 142 fPaintOptionsAndroid);
143 if (0 == newFace) { 143 if (0 == newFace) {
144 return NULL; 144 return NULL;
145 } 145 }
146 146
147 SkAutoTUnref<SkTypeface> aur(newFace); 147 SkAutoTUnref<SkTypeface> aur(newFace);
148 uint32_t newFontID = newFace->uniqueID(); 148 uint32_t newFontID = newFace->uniqueID();
149 149
150 SkOrderedWriteBuffer androidBuffer; 150 SkWriteBuffer androidBuffer;
151 fPaintOptionsAndroid.flatten(androidBuffer); 151 fPaintOptionsAndroid.flatten(androidBuffer);
152 152
153 SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.size() + SkDescriptor::C omputeOverhead(2)); 153 SkAutoDescriptor ad(sizeof(fRec) + androidBuffer.size() + SkDescriptor::C omputeOverhead(2));
154 SkDescriptor* desc = ad.getDesc(); 154 SkDescriptor* desc = ad.getDesc();
155 155
156 desc->init(); 156 desc->init();
157 SkScalerContext::Rec* newRec = 157 SkScalerContext::Rec* newRec =
158 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag, 158 (SkScalerContext::Rec*)desc->addEntry(kRec_SkDescriptorTag,
159 sizeof(fRec), &fRec); 159 sizeof(fRec), &fRec);
160 androidBuffer.writeToMemory(desc->addEntry(kAndroidOpts_SkDescriptorTag, 160 androidBuffer.writeToMemory(desc->addEntry(kAndroidOpts_SkDescriptorTag,
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, 980 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
981 bool allowFailure) const { 981 bool allowFailure) const {
982 SkScalerContext* c = this->onCreateScalerContext(desc); 982 SkScalerContext* c = this->onCreateScalerContext(desc);
983 983
984 if (!c && !allowFailure) { 984 if (!c && !allowFailure) {
985 c = SkNEW_ARGS(SkScalerContext_Empty, 985 c = SkNEW_ARGS(SkScalerContext_Empty,
986 (const_cast<SkTypeface*>(this), desc)); 986 (const_cast<SkTypeface*>(this), desc));
987 } 987 }
988 return c; 988 return c;
989 } 989 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698