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

Side by Side Diff: src/gpu/GrStrokeInfo.cpp

Issue 1116123003: Improve caching of dashed paths in GrStencilAndCoverPathRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@dashing-nvpr-01
Patch Set: Created 5 years, 7 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/gpu/GrStrokeInfo.h ('k') | src/gpu/gl/GrGLPath.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 "GrStrokeInfo.h" 8 #include "GrStrokeInfo.h"
9 9 #include "GrResourceKey.h"
10 #include "SkDashPathPriv.h" 10 #include "SkDashPathPriv.h"
11 11
12 bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, 12 bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo,
13 const SkPath& src) const { 13 const SkPath& src) const {
14 if (this->isDashed()) { 14 if (this->isDashed()) {
15 SkPathEffect::DashInfo info; 15 SkPathEffect::DashInfo info;
16 info.fIntervals = fIntervals.get(); 16 info.fIntervals = fIntervals.get();
17 info.fCount = fIntervals.count(); 17 info.fCount = fIntervals.count();
18 info.fPhase = fDashPhase; 18 info.fPhase = fDashPhase;
19 GrStrokeInfo filteredStroke(*this, false); 19 GrStrokeInfo filteredStroke(*this, false);
20 if (SkDashPath::FilterDashPath(dst, src, &filteredStroke, NULL, info)) { 20 if (SkDashPath::FilterDashPath(dst, src, &filteredStroke, NULL, info)) {
21 *dstStrokeInfo = filteredStroke; 21 *dstStrokeInfo = filteredStroke;
22 return true; 22 return true;
23 } 23 }
24 } 24 }
25 return false; 25 return false;
26 } 26 }
27
28 void GrStrokeInfo::asUniqueKeyFragment(uint32_t* data) const {
29 const int kSkScalarData32Cnt = sizeof(SkScalar) / sizeof(uint32_t);
30 enum {
31 kStyleBits = 2,
32 kJoinBits = 2,
33 kCapBits = 32 - kStyleBits - kJoinBits,
34
35 kJoinShift = kStyleBits,
36 kCapShift = kJoinShift + kJoinBits,
37 };
38
39 SK_COMPILE_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits), style_shift _will_be_wrong);
40 SK_COMPILE_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits), cap_shift_will_be _wrong);
41 SK_COMPILE_ASSERT(SkPaint::kCapCount <= (1 << kCapBits), cap_does_not_fit);
42 uint32_t styleKey = this->getStyle();
43 if (this->needToApply()) {
44 styleKey |= this->getJoin() << kJoinShift;
45 styleKey |= this->getCap() << kCapShift;
46 }
47 int i = 0;
48 data[i++] = styleKey;
49
50 // Memcpy the scalar fields. Does not "reinterpret_cast<SkScalar&>(data[i]) = ..." due to
51 // scalars having more strict alignment requirements than what data can guar antee. The
52 // compiler should optimize memcpys to assignments.
53 SkScalar scalar;
54 scalar = this->getMiter();
55 memcpy(&data[i], &scalar, sizeof(scalar));
56 i += kSkScalarData32Cnt;
57
58 scalar = this->getWidth();
59 memcpy(&data[i], &scalar, sizeof(scalar));
60 i += kSkScalarData32Cnt;
61
62 if (this->isDashed()) {
63 SkScalar phase = this->getDashPhase();
64 memcpy(&data[i], &phase, sizeof(phase));
65 i += kSkScalarData32Cnt;
66
67 int32_t count = this->getDashCount() & static_cast<int32_t>(~1);
68 SkASSERT(count == this->getDashCount());
69 const SkScalar* intervals = this->getDashIntervals();
70 int intervalByteCnt = count * sizeof(SkScalar);
71 memcpy(&data[i], intervals, intervalByteCnt);
72 // Enable the line below if fields are added after dashing.
73 SkDEBUGCODE(i += kSkScalarData32Cnt * count);
74 }
75
76 SkASSERT(this->computeUniqueKeyFragmentData32Cnt() == i);
77 }
78
OLDNEW
« no previous file with comments | « src/gpu/GrStrokeInfo.h ('k') | src/gpu/gl/GrGLPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698