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

Side by Side Diff: src/utils/SkCamera.cpp

Issue 117053002: remove SK_SCALAR_IS_[FLOAT,FIXED] and assume floats (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years 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
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 "SkCamera.h" 10 #include "SkCamera.h"
11 11
12 static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a, 12 static SkScalar SkScalarDotDiv(int count, const SkScalar a[], int step_a,
13 const SkScalar b[], int step_b, 13 const SkScalar b[], int step_b,
14 SkScalar denom) { 14 SkScalar denom) {
15 #ifdef SK_SCALAR_IS_FLOAT
16 float prod = 0; 15 float prod = 0;
17 for (int i = 0; i < count; i++) { 16 for (int i = 0; i < count; i++) {
18 prod += a[0] * b[0]; 17 prod += a[0] * b[0];
19 a += step_a; 18 a += step_a;
20 b += step_b; 19 b += step_b;
21 } 20 }
22 return prod / denom; 21 return prod / denom;
23 #else
24 Sk64 prod, tmp;
25
26 prod.set(0);
27 for (int i = 0; i < count; i++) {
28 tmp.setMul(a[0], b[0]);
29 prod.add(tmp);
30 a += step_a;
31 b += step_b;
32 }
33 prod.div(denom, Sk64::kRound_DivOption);
34 return prod.get32();
35 #endif
36 } 22 }
37 23
38 static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a, 24 static SkScalar SkScalarDot(int count, const SkScalar a[], int step_a,
39 const SkScalar b[], int step_b) { 25 const SkScalar b[], int step_b) {
40 #ifdef SK_SCALAR_IS_FLOAT
41 float prod = 0; 26 float prod = 0;
42 for (int i = 0; i < count; i++) { 27 for (int i = 0; i < count; i++) {
43 prod += a[0] * b[0]; 28 prod += a[0] * b[0];
44 a += step_a; 29 a += step_a;
45 b += step_b; 30 b += step_b;
46 } 31 }
47 return prod; 32 return prod;
48 #else
49 Sk64 prod, tmp;
50
51 prod.set(0);
52 for (int i = 0; i < count; i++) {
53 tmp.setMul(a[0], b[0]);
54 prod.add(tmp);
55 a += step_a;
56 b += step_b;
57 }
58 return prod.getFixed();
59 #endif
60 } 33 }
61 34
62 /////////////////////////////////////////////////////////////////////////////// 35 ///////////////////////////////////////////////////////////////////////////////
63 36
64 SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const { 37 SkUnitScalar SkPoint3D::normalize(SkUnit3D* unit) const {
65 #ifdef SK_SCALAR_IS_FLOAT
66 float mag = sk_float_sqrt(fX*fX + fY*fY + fZ*fZ); 38 float mag = sk_float_sqrt(fX*fX + fY*fY + fZ*fZ);
67 if (mag) { 39 if (mag) {
68 float scale = 1.0f / mag; 40 float scale = 1.0f / mag;
69 unit->fX = fX * scale; 41 unit->fX = fX * scale;
70 unit->fY = fY * scale; 42 unit->fY = fY * scale;
71 unit->fZ = fZ * scale; 43 unit->fZ = fZ * scale;
72 } else { 44 } else {
73 unit->fX = unit->fY = unit->fZ = 0; 45 unit->fX = unit->fY = unit->fZ = 0;
74 } 46 }
75 #else
76 Sk64 tmp1, tmp2;
77
78 tmp1.setMul(fX, fX);
79 tmp2.setMul(fY, fY);
80 tmp1.add(tmp2);
81 tmp2.setMul(fZ, fZ);
82 tmp1.add(tmp2);
83
84 SkFixed mag = tmp1.getSqrt();
85 if (mag) {
86 // what if mag < SK_Fixed1 ??? we will underflow the fixdiv
87 SkFixed scale = SkFixedDiv(SK_Fract1, mag);
88 unit->fX = SkFixedMul(fX, scale);
89 unit->fY = SkFixedMul(fY, scale);
90 unit->fZ = SkFixedMul(fZ, scale);
91 } else {
92 unit->fX = unit->fY = unit->fZ = 0;
93 }
94 #endif
95 return mag; 47 return mag;
96 } 48 }
97 49
98 SkUnitScalar SkUnit3D::Dot(const SkUnit3D& a, const SkUnit3D& b) { 50 SkUnitScalar SkUnit3D::Dot(const SkUnit3D& a, const SkUnit3D& b) {
99 return SkUnitScalarMul(a.fX, b.fX) + 51 return SkUnitScalarMul(a.fX, b.fX) +
100 SkUnitScalarMul(a.fY, b.fY) + 52 SkUnitScalarMul(a.fY, b.fY) +
101 SkUnitScalarMul(a.fZ, b.fZ); 53 SkUnitScalarMul(a.fZ, b.fZ);
102 } 54 }
103 55
104 void SkUnit3D::Cross(const SkUnit3D& a, const SkUnit3D& b, SkUnit3D* cross) { 56 void SkUnit3D::Cross(const SkUnit3D& a, const SkUnit3D& b, SkUnit3D* cross) {
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 } 368 }
417 369
418 #include "SkCanvas.h" 370 #include "SkCanvas.h"
419 371
420 void Sk3DView::applyToCanvas(SkCanvas* canvas) const { 372 void Sk3DView::applyToCanvas(SkCanvas* canvas) const {
421 SkMatrix matrix; 373 SkMatrix matrix;
422 374
423 this->getMatrix(&matrix); 375 this->getMatrix(&matrix);
424 canvas->concat(matrix); 376 canvas->concat(matrix);
425 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698