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

Unified Diff: sky/engine/core/painting/Rect.cpp

Issue 1151673002: Sky: different tack for custom Rect type in the Canvas API. (Closed) Base URL: git@github.com:/domokit/mojo.git@master
Patch Set: Float32List Created 5 years, 7 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 | « sky/engine/core/painting/Rect.h ('k') | sky/engine/core/painting/Rect.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/engine/core/painting/Rect.cpp
diff --git a/sky/engine/core/painting/Rect.cpp b/sky/engine/core/painting/Rect.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4a0c643cc8bd09ed69f8c0e8da2e3fda36bd3ad7
--- /dev/null
+++ b/sky/engine/core/painting/Rect.cpp
@@ -0,0 +1,53 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sky/engine/config.h"
+#include "sky/engine/core/painting/Rect.h"
+
+#include "sky/engine/tonic/dart_error.h"
+#include "sky/engine/tonic/dart_state.h"
+#include "base/logging.h"
+
+namespace blink {
+
+// Convert dart_rect._value[0...3] ==> SkRect.
+Rect DartConverter<Rect, void>::FromArgumentsWithNullCheck(
+ Dart_NativeArguments args,
+ int index,
+ Dart_Handle& exception) {
+ Rect result;
+ result.is_null = true;
+
+ Dart_Handle dart_rect = Dart_GetNativeArgument(args, index);
+ DCHECK(!LogIfError(dart_rect));
+
+ Dart_Handle value = Dart_GetField(dart_rect,
+ Dart_NewStringFromCString("_value"));
+ if (Dart_IsNull(value))
+ return result;
+
+ Dart_TypedData_Type type;
+ float* data = nullptr;
+ intptr_t num_elements = 0;
+ Dart_TypedDataAcquireData(
+ value, &type, reinterpret_cast<void**>(&data), &num_elements);
+ DCHECK(!LogIfError(value));
+ ASSERT(type == Dart_TypedData_kFloat32 && num_elements == 4);
+
+ SkScalar* dest[] = {
+ &result.sk_rect.fLeft,
+ &result.sk_rect.fTop,
+ &result.sk_rect.fRight,
+ &result.sk_rect.fBottom
+ };
+ for (intptr_t i = 0; i < 4; ++i)
+ *dest[i] = data[i];
+
+ Dart_TypedDataReleaseData(value);
+
+ result.is_null = false;
+ return result;
+}
+
+} // namespace blink
« no previous file with comments | « sky/engine/core/painting/Rect.h ('k') | sky/engine/core/painting/Rect.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698