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 "mojo/skia/type_converters.h" |
| 6 |
| 7 namespace mojo { |
| 8 |
| 9 SkPoint TypeConverter<SkPoint, mojo::Point>::Convert(const mojo::Point& input) { |
| 10 return SkPoint::Make(input.x, input.y); |
| 11 } |
| 12 |
| 13 mojo::Point TypeConverter<mojo::Point, SkPoint>::Convert(const SkPoint& input) { |
| 14 mojo::Point output; |
| 15 output.x = input.x(); |
| 16 output.y = input.y(); |
| 17 return output; |
| 18 } |
| 19 |
| 20 SkRect TypeConverter<SkRect, mojo::Rect>::Convert(const mojo::Rect& input) { |
| 21 return SkRect::MakeXYWH(input.x, input.y, input.width, input.height); |
| 22 } |
| 23 |
| 24 mojo::Rect TypeConverter<mojo::Rect, SkRect>::Convert(const SkRect& input) { |
| 25 mojo::Rect output; |
| 26 output.x = input.x(); |
| 27 output.y = input.y(); |
| 28 output.width = input.width(); |
| 29 output.height = input.height(); |
| 30 return output; |
| 31 } |
| 32 |
| 33 SkRRect TypeConverter<SkRRect, mojo::RRect>::Convert(const mojo::RRect& input) { |
| 34 SkVector radii[4] = { |
| 35 {input.top_left_radius_x, input.top_left_radius_y}, |
| 36 {input.top_right_radius_x, input.top_right_radius_y}, |
| 37 {input.bottom_left_radius_x, input.bottom_left_radius_y}, |
| 38 {input.bottom_right_radius_x, input.bottom_right_radius_y}}; |
| 39 SkRRect output; |
| 40 output.setRectRadii( |
| 41 SkRect::MakeXYWH(input.x, input.y, input.width, input.height), radii); |
| 42 return output; |
| 43 } |
| 44 |
| 45 mojo::RRect TypeConverter<mojo::RRect, SkRRect>::Convert(const SkRRect& input) { |
| 46 mojo::RRect output; |
| 47 output.x = input.rect().x(); |
| 48 output.y = input.rect().y(); |
| 49 output.width = input.rect().width(); |
| 50 output.height = input.rect().height(); |
| 51 output.top_left_radius_x = input.radii(SkRRect::kUpperLeft_Corner).x(); |
| 52 output.top_left_radius_y = input.radii(SkRRect::kUpperLeft_Corner).y(); |
| 53 output.top_right_radius_x = input.radii(SkRRect::kUpperRight_Corner).x(); |
| 54 output.top_right_radius_y = input.radii(SkRRect::kUpperRight_Corner).y(); |
| 55 output.bottom_left_radius_x = input.radii(SkRRect::kLowerLeft_Corner).x(); |
| 56 output.bottom_left_radius_y = input.radii(SkRRect::kLowerLeft_Corner).y(); |
| 57 output.bottom_right_radius_x = input.radii(SkRRect::kLowerRight_Corner).x(); |
| 58 output.bottom_right_radius_y = input.radii(SkRRect::kLowerRight_Corner).y(); |
| 59 return output; |
| 60 } |
| 61 |
| 62 SkMatrix TypeConverter<SkMatrix, mojo::TransformPtr>::Convert( |
| 63 const mojo::TransformPtr& input) { |
| 64 if (!input) |
| 65 return SkMatrix::I(); |
| 66 |
| 67 // Drop 3D components during conversion from 4x4 to 3x3. |
| 68 SkMatrix output; |
| 69 output.setAll(input->matrix[0], input->matrix[1], input->matrix[3], |
| 70 input->matrix[4], input->matrix[5], input->matrix[7], |
| 71 input->matrix[12], input->matrix[13], input->matrix[15]); |
| 72 return output; |
| 73 } |
| 74 |
| 75 mojo::TransformPtr TypeConverter<mojo::TransformPtr, SkMatrix>::Convert( |
| 76 const SkMatrix& input) { |
| 77 // Expand 3x3 to 4x4. |
| 78 auto output = mojo::Transform::New(); |
| 79 output->matrix.resize(16u); |
| 80 output->matrix[0] = input[0]; |
| 81 output->matrix[1] = input[1]; |
| 82 output->matrix[2] = 0.f; |
| 83 output->matrix[3] = input[2]; |
| 84 output->matrix[4] = input[3]; |
| 85 output->matrix[5] = input[4]; |
| 86 output->matrix[6] = 0.f; |
| 87 output->matrix[7] = input[5]; |
| 88 output->matrix[8] = 0.f; |
| 89 output->matrix[9] = 0.f; |
| 90 output->matrix[10] = 1.f; |
| 91 output->matrix[11] = 0.f; |
| 92 output->matrix[12] = input[6]; |
| 93 output->matrix[13] = input[7]; |
| 94 output->matrix[14] = 0.f; |
| 95 output->matrix[15] = input[8]; |
| 96 return output.Pass(); |
| 97 } |
| 98 |
| 99 } // namespace mojo |
OLD | NEW |