OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "content/renderer/skia_benchmarking_extension.h" | 5 #include "content/renderer/skia_benchmarking_extension.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
14 #include "content/public/child/v8_value_converter.h" | 14 #include "content/public/child/v8_value_converter.h" |
15 #include "content/public/renderer/chrome_object_extensions_utils.h" | 15 #include "content/public/renderer/chrome_object_extensions_utils.h" |
16 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
17 #include "gin/arguments.h" | 17 #include "gin/arguments.h" |
| 18 #include "gin/data_object_builder.h" |
18 #include "gin/handle.h" | 19 #include "gin/handle.h" |
19 #include "gin/object_template_builder.h" | 20 #include "gin/object_template_builder.h" |
20 #include "skia/ext/benchmarking_canvas.h" | 21 #include "skia/ext/benchmarking_canvas.h" |
21 #include "third_party/WebKit/public/web/WebArrayBuffer.h" | 22 #include "third_party/WebKit/public/web/WebArrayBuffer.h" |
22 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" | 23 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 24 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "third_party/WebKit/public/web/WebKit.h" | 25 #include "third_party/WebKit/public/web/WebKit.h" |
25 #include "third_party/skia/include/core/SkCanvas.h" | 26 #include "third_party/skia/include/core/SkCanvas.h" |
26 #include "third_party/skia/include/core/SkColorPriv.h" | 27 #include "third_party/skia/include/core/SkColorPriv.h" |
27 #include "third_party/skia/include/core/SkGraphics.h" | 28 #include "third_party/skia/include/core/SkGraphics.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 uint8_t* buffer_pixels = reinterpret_cast<uint8_t*>(buffer.Data()); | 252 uint8_t* buffer_pixels = reinterpret_cast<uint8_t*>(buffer.Data()); |
252 // Swizzle from native Skia format to RGBA as we copy out. | 253 // Swizzle from native Skia format to RGBA as we copy out. |
253 for (size_t i = 0; i < bitmap.getSize(); i += 4) { | 254 for (size_t i = 0; i < bitmap.getSize(); i += 4) { |
254 uint32_t c = packed_pixels[i >> 2]; | 255 uint32_t c = packed_pixels[i >> 2]; |
255 buffer_pixels[i] = SkGetPackedR32(c); | 256 buffer_pixels[i] = SkGetPackedR32(c); |
256 buffer_pixels[i + 1] = SkGetPackedG32(c); | 257 buffer_pixels[i + 1] = SkGetPackedG32(c); |
257 buffer_pixels[i + 2] = SkGetPackedB32(c); | 258 buffer_pixels[i + 2] = SkGetPackedB32(c); |
258 buffer_pixels[i + 3] = SkGetPackedA32(c); | 259 buffer_pixels[i + 3] = SkGetPackedA32(c); |
259 } | 260 } |
260 | 261 |
261 v8::Local<v8::Object> result = v8::Object::New(isolate); | 262 args->Return(gin::DataObjectBuilder(isolate) |
262 result->Set(v8::String::NewFromUtf8(isolate, "width"), | 263 .Set("width", snapped_clip.width()) |
263 v8::Number::New(isolate, snapped_clip.width())); | 264 .Set("height", snapped_clip.height()) |
264 result->Set(v8::String::NewFromUtf8(isolate, "height"), | 265 .Set("data", blink::WebArrayBufferConverter::ToV8Value( |
265 v8::Number::New(isolate, snapped_clip.height())); | 266 &buffer, context->Global(), isolate)) |
266 result->Set(v8::String::NewFromUtf8(isolate, "data"), | 267 .Finish()); |
267 blink::WebArrayBufferConverter::ToV8Value( | |
268 &buffer, context->Global(), isolate)); | |
269 | |
270 args->Return(result); | |
271 } | 268 } |
272 | 269 |
273 void SkiaBenchmarking::GetOps(gin::Arguments* args) { | 270 void SkiaBenchmarking::GetOps(gin::Arguments* args) { |
274 v8::Isolate* isolate = args->isolate(); | 271 v8::Isolate* isolate = args->isolate(); |
275 if (args->PeekNext().IsEmpty()) | 272 if (args->PeekNext().IsEmpty()) |
276 return; | 273 return; |
277 v8::Local<v8::Value> picture_handle; | 274 v8::Local<v8::Value> picture_handle; |
278 args->GetNext(&picture_handle); | 275 args->GetNext(&picture_handle); |
279 std::unique_ptr<Picture> picture = ParsePictureHash(isolate, picture_handle); | 276 std::unique_ptr<Picture> picture = ParsePictureHash(isolate, picture_handle); |
280 if (!picture.get()) | 277 if (!picture.get()) |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 v8::Local<v8::Object> result = v8::Object::New(isolate); | 342 v8::Local<v8::Object> result = v8::Object::New(isolate); |
346 result->Set(v8::String::NewFromUtf8(isolate, "width"), | 343 result->Set(v8::String::NewFromUtf8(isolate, "width"), |
347 v8::Number::New(isolate, picture->layer_rect.width())); | 344 v8::Number::New(isolate, picture->layer_rect.width())); |
348 result->Set(v8::String::NewFromUtf8(isolate, "height"), | 345 result->Set(v8::String::NewFromUtf8(isolate, "height"), |
349 v8::Number::New(isolate, picture->layer_rect.height())); | 346 v8::Number::New(isolate, picture->layer_rect.height())); |
350 | 347 |
351 args->Return(result); | 348 args->Return(result); |
352 } | 349 } |
353 | 350 |
354 } // namespace content | 351 } // namespace content |
OLD | NEW |