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

Unified Diff: ui/gfx/mojo/transform_struct_traits.h

Issue 2210673002: Improve gfx::Transform StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/mojo/transform.typemap ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/mojo/transform_struct_traits.h
diff --git a/ui/gfx/mojo/transform_struct_traits.h b/ui/gfx/mojo/transform_struct_traits.h
index df51a6fbb5781a057d9457cee74e52bd7392c399..a55122e40733067214ba5c6175ea5f06056df320 100644
--- a/ui/gfx/mojo/transform_struct_traits.h
+++ b/ui/gfx/mojo/transform_struct_traits.h
@@ -5,26 +5,34 @@
#ifndef UI_GFX_MOJO_TRANSFORM_STRUCT_TRAITS_H_
#define UI_GFX_MOJO_TRANSFORM_STRUCT_TRAITS_H_
+#include "mojo/public/cpp/bindings/array_traits.h"
#include "ui/gfx/mojo/transform.mojom.h"
#include "ui/gfx/transform.h"
namespace mojo {
template <>
+struct ArrayTraits<SkMatrix44> {
+ using Element = float;
+
+ static size_t GetSize(const SkMatrix44& input) { return 16; }
+
+ static float GetAt(const SkMatrix44& input, size_t index) {
+ return input.getFloat(static_cast<int>(index % 4),
+ static_cast<int>(index / 4));
+ }
+};
+
+template <>
struct StructTraits<gfx::mojom::Transform, gfx::Transform> {
- static mojo::Array<float> matrix(const gfx::Transform& transform) {
- std::vector<float> storage(16);
- transform.matrix().asRowMajorf(&storage[0]);
- mojo::Array<float> matrix;
- matrix.Swap(&storage);
- return matrix;
+ static const SkMatrix44& matrix(const gfx::Transform& transform) {
+ return transform.matrix();
}
static bool Read(gfx::mojom::TransformDataView data, gfx::Transform* out) {
- mojo::Array<float> matrix;
- if (!data.ReadMatrix(&matrix))
- return false;
- out->matrix().setRowMajorf(&matrix.storage()[0]);
+ ArrayDataView<float> matrix;
+ data.GetMatrixDataView(&matrix);
Tom Sepez 2016/08/04 17:36:03 How do we know that data is big enough, e.g well-f
yzshen1 2016/08/04 17:38:16 Before we reach here, the standard validation logi
+ out->matrix().setColMajorf(matrix.data());
return true;
}
};
« no previous file with comments | « ui/gfx/mojo/transform.typemap ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698