OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/client/gl_math.h" | 5 #include "remoting/client/gl_math.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
11 // | m0, m1, m2, | | Scale_x 0 Offset_x | | 11 // | m0, m1, m2, | | Scale_x Skew_x Offset_x | |
12 // | m3, m4, m5, | = | 0 Scale_y Offset_y | | 12 // | m3, m4, m5, | = | Skew_y Scale_y Offset_y | |
13 // | m6, m7, m8 | | 0 0 1 | | 13 // | m6, m7, m8 | | 0 0 1 | |
14 | 14 |
15 const int kXScaleKey = 0; | 15 const int kXScaleKey = 0; |
| 16 const int kXSkewKey = 1; |
| 17 const int kXOffsetKey = 2; |
| 18 |
| 19 const int kYSkewKey = 3; |
16 const int kYScaleKey = 4; | 20 const int kYScaleKey = 4; |
17 const int kXOffsetKey = 2; | |
18 const int kYOffsetKey = 5; | 21 const int kYOffsetKey = 5; |
19 | 22 |
| 23 const int kXOffsetTransposedKey = 6; |
| 24 const int kYOffsetTransposedKey = 7; |
| 25 |
20 } // namespace | 26 } // namespace |
21 | 27 |
22 namespace remoting { | 28 namespace remoting { |
23 | 29 |
24 void NormalizeTransformationMatrix(int view_width, | 30 void NormalizeTransformationMatrix(int view_width, |
25 int view_height, | 31 int view_height, |
26 int canvas_width, | 32 int canvas_width, |
27 int canvas_height, | 33 int canvas_height, |
28 std::array<float, 9>* matrix) { | 34 std::array<float, 9>* matrix) { |
29 (*matrix)[kXScaleKey] = canvas_width * (*matrix)[kXScaleKey] / view_width; | 35 (*matrix)[kXScaleKey] = canvas_width * (*matrix)[kXScaleKey] / view_width; |
30 (*matrix)[kYScaleKey] = canvas_height * (*matrix)[kYScaleKey] / view_height; | 36 (*matrix)[kYScaleKey] = canvas_height * (*matrix)[kYScaleKey] / view_height; |
31 (*matrix)[kXOffsetKey] /= view_width; | 37 (*matrix)[kXOffsetKey] /= view_width; |
32 (*matrix)[kYOffsetKey] /= view_height; | 38 (*matrix)[kYOffsetKey] /= view_height; |
33 } | 39 } |
34 | 40 |
| 41 void TransposeTransformationMatrix(std::array<float, 9>* matrix) { |
| 42 std::swap((*matrix)[kXOffsetKey], (*matrix)[kXOffsetTransposedKey]); |
| 43 std::swap((*matrix)[kYOffsetKey], (*matrix)[kYOffsetTransposedKey]); |
| 44 std::swap((*matrix)[kXSkewKey], (*matrix)[kYSkewKey]); |
| 45 } |
| 46 |
35 void FillRectangleVertexPositions(float left, | 47 void FillRectangleVertexPositions(float left, |
36 float top, | 48 float top, |
37 float width, | 49 float width, |
38 float height, | 50 float height, |
39 std::array<float, 8>* positions) { | 51 std::array<float, 8>* positions) { |
40 (*positions)[0] = left; | 52 (*positions)[0] = left; |
41 (*positions)[1] = top; | 53 (*positions)[1] = top; |
42 | 54 |
43 (*positions)[2] = left; | 55 (*positions)[2] = left; |
44 (*positions)[3] = top + height; | 56 (*positions)[3] = top + height; |
(...skipping 12 matching lines...) Expand all Loading... |
57 for (int j = 0; j < num_cols; j++) { | 69 for (int j = 0; j < num_cols; j++) { |
58 outstream << mat[i * num_cols + j] << ", "; | 70 outstream << mat[i * num_cols + j] << ", "; |
59 } | 71 } |
60 outstream << "\n"; | 72 outstream << "\n"; |
61 } | 73 } |
62 outstream << "]"; | 74 outstream << "]"; |
63 return outstream.str(); | 75 return outstream.str(); |
64 } | 76 } |
65 | 77 |
66 } // namespace remoting | 78 } // namespace remoting |
OLD | NEW |