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

Side by Side Diff: src/effects/gradients/SkSweepGradient.cpp

Issue 249643002: Revert of Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
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 #include "SkSweepGradient.h" 9 #include "SkSweepGradient.h"
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 SkSweepGradient::SkSweepGradient(SkReadBuffer& buffer) 45 SkSweepGradient::SkSweepGradient(SkReadBuffer& buffer)
46 : INHERITED(buffer), 46 : INHERITED(buffer),
47 fCenter(buffer.readPoint()) { 47 fCenter(buffer.readPoint()) {
48 } 48 }
49 49
50 void SkSweepGradient::flatten(SkWriteBuffer& buffer) const { 50 void SkSweepGradient::flatten(SkWriteBuffer& buffer) const {
51 this->INHERITED::flatten(buffer); 51 this->INHERITED::flatten(buffer);
52 buffer.writePoint(fCenter); 52 buffer.writePoint(fCenter);
53 } 53 }
54 54
55 size_t SkSweepGradient::contextSize() const {
56 return sizeof(SweepGradientContext);
57 }
58
59 SkShader::Context* SkSweepGradient::createContext(const SkBitmap& device, const SkPaint& paint,
60 const SkMatrix& matrix, void* storage) const {
61 if (!this->validContext(device, paint, matrix)) {
62 return NULL;
63 }
64
65 return SkNEW_PLACEMENT_ARGS(storage, SweepGradientContext, (*this, device, p aint, matrix));
66 }
67
68 SkSweepGradient::SweepGradientContext::SweepGradientContext(
69 const SkSweepGradient& shader, const SkBitmap& device,
70 const SkPaint& paint, const SkMatrix& matrix)
71 : INHERITED(shader, device, paint, matrix) {}
72
73 // returns angle in a circle [0..2PI) -> [0..255] 55 // returns angle in a circle [0..2PI) -> [0..255]
74 static unsigned SkATan2_255(float y, float x) { 56 static unsigned SkATan2_255(float y, float x) {
75 // static const float g255Over2PI = 255 / (2 * SK_ScalarPI); 57 // static const float g255Over2PI = 255 / (2 * SK_ScalarPI);
76 static const float g255Over2PI = 40.584510488433314f; 58 static const float g255Over2PI = 40.584510488433314f;
77 59
78 float result = sk_float_atan2(y, x); 60 float result = sk_float_atan2(y, x);
79 if (result < 0) { 61 if (result < 0) {
80 result += 2 * SK_ScalarPI; 62 result += 2 * SK_ScalarPI;
81 } 63 }
82 SkASSERT(result >= 0); 64 SkASSERT(result >= 0);
83 // since our value is always >= 0, we can cast to int, which is faster than 65 // since our value is always >= 0, we can cast to int, which is faster than
84 // calling floorf() 66 // calling floorf()
85 int ir = (int)(result * g255Over2PI); 67 int ir = (int)(result * g255Over2PI);
86 SkASSERT(ir >= 0 && ir <= 255); 68 SkASSERT(ir >= 0 && ir <= 255);
87 return ir; 69 return ir;
88 } 70 }
89 71
90 void SkSweepGradient::SweepGradientContext::shadeSpan(int x, int y, SkPMColor* S K_RESTRICT dstC, 72 void SkSweepGradient::shadeSpan(int x, int y, SkPMColor* SK_RESTRICT dstC,
91 int count) { 73 int count) {
92 SkMatrix::MapXYProc proc = fDstToIndexProc; 74 SkMatrix::MapXYProc proc = fDstToIndexProc;
93 const SkMatrix& matrix = fDstToIndex; 75 const SkMatrix& matrix = fDstToIndex;
94 const SkPMColor* SK_RESTRICT cache = fCache->getCache32(); 76 const SkPMColor* SK_RESTRICT cache = this->getCache32();
95 int toggle = init_dither_toggle(x, y); 77 int toggle = init_dither_toggle(x, y);
96 SkPoint srcPt; 78 SkPoint srcPt;
97 79
98 if (fDstToIndexClass != kPerspective_MatrixClass) { 80 if (fDstToIndexClass != kPerspective_MatrixClass) {
99 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, 81 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
100 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 82 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
101 SkScalar dx, fx = srcPt.fX; 83 SkScalar dx, fx = srcPt.fX;
102 SkScalar dy, fy = srcPt.fY; 84 SkScalar dy, fy = srcPt.fY;
103 85
104 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { 86 if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
(...skipping 17 matching lines...) Expand all
122 } else { // perspective case 104 } else { // perspective case
123 for (int stop = x + count; x < stop; x++) { 105 for (int stop = x + count; x < stop; x++) {
124 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, 106 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
125 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 107 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
126 *dstC++ = cache[toggle + SkATan2_255(srcPt.fY, srcPt.fX)]; 108 *dstC++ = cache[toggle + SkATan2_255(srcPt.fY, srcPt.fX)];
127 toggle = next_dither_toggle(toggle); 109 toggle = next_dither_toggle(toggle);
128 } 110 }
129 } 111 }
130 } 112 }
131 113
132 void SkSweepGradient::SweepGradientContext::shadeSpan16(int x, int y, uint16_t* SK_RESTRICT dstC, 114 void SkSweepGradient::shadeSpan16(int x, int y, uint16_t* SK_RESTRICT dstC,
133 int count) { 115 int count) {
134 SkMatrix::MapXYProc proc = fDstToIndexProc; 116 SkMatrix::MapXYProc proc = fDstToIndexProc;
135 const SkMatrix& matrix = fDstToIndex; 117 const SkMatrix& matrix = fDstToIndex;
136 const uint16_t* SK_RESTRICT cache = fCache->getCache16(); 118 const uint16_t* SK_RESTRICT cache = this->getCache16();
137 int toggle = init_dither_toggle16(x, y); 119 int toggle = init_dither_toggle16(x, y);
138 SkPoint srcPt; 120 SkPoint srcPt;
139 121
140 if (fDstToIndexClass != kPerspective_MatrixClass) { 122 if (fDstToIndexClass != kPerspective_MatrixClass) {
141 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf, 123 proc(matrix, SkIntToScalar(x) + SK_ScalarHalf,
142 SkIntToScalar(y) + SK_ScalarHalf, &srcPt); 124 SkIntToScalar(y) + SK_ScalarHalf, &srcPt);
143 SkScalar dx, fx = srcPt.fX; 125 SkScalar dx, fx = srcPt.fX;
144 SkScalar dy, fy = srcPt.fY; 126 SkScalar dy, fy = srcPt.fY;
145 127
146 if (fDstToIndexClass == kFixedStepInX_MatrixClass) { 128 if (fDstToIndexClass == kFixedStepInX_MatrixClass) {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 str->appendScalar(fCenter.fX); 293 str->appendScalar(fCenter.fX);
312 str->append(", "); 294 str->append(", ");
313 str->appendScalar(fCenter.fY); 295 str->appendScalar(fCenter.fY);
314 str->append(") "); 296 str->append(") ");
315 297
316 this->INHERITED::toString(str); 298 this->INHERITED::toString(str);
317 299
318 str->append(")"); 300 str->append(")");
319 } 301 }
320 #endif 302 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkSweepGradient.h ('k') | src/effects/gradients/SkTwoPointConicalGradient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698