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

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

Issue 24350006: Move bound and isFinite into pathref (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Added TODO Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkPathRef.h ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 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 "SkBuffer.h"
9 #include "SkPath.h"
10 #include "SkPathRef.h"
11
12 SK_DEFINE_INST_COUNT(SkPathRef);
13
14 SkPoint* SkPathRef::Editor::growForVerb(int /*SkPath::Verb*/ verb) {
15 fPathRef->validate();
16 return fPathRef->growForVerb(verb);
17 }
18
19 SkPoint* SkPathRef::Editor::growForConic(SkScalar w) {
20 fPathRef->validate();
21 SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb);
22 *fPathRef->fConicWeights.append() = w;
23 return pts;
24 }
25
26 SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) {
27 this->validate();
28 int pCnt;
29 switch (verb) {
30 case SkPath::kMove_Verb:
31 pCnt = 1;
32 break;
33 case SkPath::kLine_Verb:
34 pCnt = 1;
35 break;
36 case SkPath::kQuad_Verb:
37 // fall through
38 case SkPath::kConic_Verb:
39 pCnt = 2;
40 break;
41 case SkPath::kCubic_Verb:
42 pCnt = 3;
43 break;
44 case SkPath::kClose_Verb:
45 pCnt = 0;
46 break;
47 case SkPath::kDone_Verb:
48 SkDEBUGFAIL("growForVerb called for kDone");
49 // fall through
50 default:
51 SkDEBUGFAIL("default is not reached");
52 pCnt = 0;
53 }
54 size_t space = sizeof(uint8_t) + pCnt * sizeof (SkPoint);
55 this->makeSpace(space);
56 this->fVerbs[~fVerbCnt] = verb;
57 SkPoint* ret = fPoints + fPointCnt;
58 fVerbCnt += 1;
59 fPointCnt += pCnt;
60 fFreeSpace -= space;
61 fBoundsIsDirty = true; // this also invalidates fIsFinite
62 this->validate();
63 return ret;
64 }
65
66 SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer
67 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
68 , bool newFormat, int32_t oldPacked
69 #endif
70 ) {
71 SkPathRef* ref = SkNEW(SkPathRef);
72 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
73 if (newFormat) {
74 #endif
75 int32_t packed = buffer->readU32();
76
77 ref->fIsFinite = (packed >> kIsFinite_SerializationShift) & 1;
78 #ifndef DELETE_THIS_CODE_WHEN_SKPS_ARE_REBUILT_AT_V14_AND_ALL_OTHER_INSTANCES_TO O
79 } else {
80 ref->fIsFinite = (oldPacked >> SkPath::kOldIsFinite_SerializationShift) & 1;
81 }
82 #endif
83
84 ref->fGenerationID = buffer->readU32();
85 int32_t verbCount = buffer->readS32();
86 int32_t pointCount = buffer->readS32();
87 int32_t conicCount = buffer->readS32();
88 ref->resetToSize(verbCount, pointCount, conicCount);
89
90 SkASSERT(verbCount == ref->countVerbs());
91 SkASSERT(pointCount == ref->countPoints());
92 SkASSERT(conicCount == ref->fConicWeights.count());
93 buffer->read(ref->verbsMemWritable(), verbCount * sizeof(uint8_t));
94 buffer->read(ref->fPoints, pointCount * sizeof(SkPoint));
95 buffer->read(ref->fConicWeights.begin(), conicCount * sizeof(SkScalar));
96 buffer->read(&ref->fBounds, sizeof(SkRect));
97 ref->fBoundsIsDirty = false;
98 return ref;
99 }
100
101 /**
102 * Writes the path points and verbs to a buffer.
103 */
104 void SkPathRef::writeToBuffer(SkWBuffer* buffer) {
105 this->validate();
106 SkDEBUGCODE(size_t beforePos = buffer->pos();)
107
108 // Call getBounds() to ensure (as a side-effect) that fBounds
109 // and fIsFinite are computed.
110 const SkRect& bounds = this->getBounds();
111
112 int32_t packed = ((fIsFinite & 1) << kIsFinite_SerializationShift);
113 buffer->write32(packed);
114
115 // TODO: write gen ID here. Problem: We don't know if we're cross process or not from
116 // SkWBuffer. Until this is fixed we write 0.
117 buffer->write32(0);
118 buffer->write32(fVerbCnt);
119 buffer->write32(fPointCnt);
120 buffer->write32(fConicWeights.count());
121 buffer->write(verbsMemBegin(), fVerbCnt * sizeof(uint8_t));
122 buffer->write(fPoints, fPointCnt * sizeof(SkPoint));
123 buffer->write(fConicWeights.begin(), fConicWeights.bytes());
124 buffer->write(&bounds, sizeof(bounds));
125
126 SkASSERT(buffer->pos() - beforePos == (size_t) this->writeSize());
127 }
OLDNEW
« no previous file with comments | « src/core/SkPathRef.h ('k') | src/core/SkPicture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698