OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/client/gl_math.h" |
| 6 |
| 7 #include <sstream> |
| 8 |
| 9 namespace { |
| 10 |
| 11 // | m0, m1, m2, | | Scale_x 0 Offset_x | |
| 12 // | m3, m4, m5, | = | 0 Scale_y Offset_y | |
| 13 // | m6, m7, m8 | | 0 0 1 | |
| 14 |
| 15 const int kXScaleKey = 0; |
| 16 const int kYScaleKey = 4; |
| 17 const int kXOffsetKey = 2; |
| 18 const int kYOffsetKey = 5; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 namespace remoting { |
| 23 |
| 24 void NormalizeTransformationMatrix(int view_width, |
| 25 int view_height, |
| 26 int canvas_width, |
| 27 int canvas_height, |
| 28 std::array<float, 9>* matrix) { |
| 29 (*matrix)[kXScaleKey] = canvas_width * (*matrix)[kXScaleKey] / view_width; |
| 30 (*matrix)[kYScaleKey] = canvas_height * (*matrix)[kYScaleKey] / view_height; |
| 31 (*matrix)[kXOffsetKey] /= view_width; |
| 32 (*matrix)[kYOffsetKey] /= view_height; |
| 33 } |
| 34 |
| 35 void FillRectangleVertexPositions(float left, |
| 36 float top, |
| 37 float width, |
| 38 float height, |
| 39 std::array<float, 8>* positions) { |
| 40 (*positions)[0] = left; |
| 41 (*positions)[1] = top; |
| 42 |
| 43 (*positions)[2] = left; |
| 44 (*positions)[3] = top + height; |
| 45 |
| 46 (*positions)[4] = left + width; |
| 47 (*positions)[5] = top; |
| 48 |
| 49 (*positions)[6] = left + width; |
| 50 (*positions)[7] = top + height; |
| 51 } |
| 52 |
| 53 std::string MatrixToString(const float* mat, int num_rows, int num_cols) { |
| 54 std::ostringstream outstream; |
| 55 outstream << "[\n"; |
| 56 for (int i = 0; i < num_rows; i++) { |
| 57 for (int j = 0; j < num_cols; j++) { |
| 58 outstream << mat[i * num_cols + j] << ", "; |
| 59 } |
| 60 outstream << "\n"; |
| 61 } |
| 62 outstream << "]"; |
| 63 return outstream.str(); |
| 64 } |
| 65 |
| 66 } // namespace remoting |
OLD | NEW |