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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "cc/base/math_util.h" | 10 #include "cc/base/math_util.h" |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 for (size_t i = 0; i < bitmap.getSize(); i += 4) { | 215 for (size_t i = 0; i < bitmap.getSize(); i += 4) { |
216 uint32 c = packed_pixels[i >> 2]; | 216 uint32 c = packed_pixels[i >> 2]; |
217 buffer_pixels[i] = SkGetPackedR32(c); | 217 buffer_pixels[i] = SkGetPackedR32(c); |
218 buffer_pixels[i + 1] = SkGetPackedG32(c); | 218 buffer_pixels[i + 1] = SkGetPackedG32(c); |
219 buffer_pixels[i + 2] = SkGetPackedB32(c); | 219 buffer_pixels[i + 2] = SkGetPackedB32(c); |
220 buffer_pixels[i + 3] = SkGetPackedA32(c); | 220 buffer_pixels[i + 3] = SkGetPackedA32(c); |
221 } | 221 } |
222 | 222 |
223 v8::Handle<v8::Object> result = v8::Object::New(isolate); | 223 v8::Handle<v8::Object> result = v8::Object::New(isolate); |
224 result->Set(v8::String::NewFromUtf8(isolate, "width"), | 224 result->Set(v8::String::NewFromUtf8(isolate, "width"), |
225 v8::Number::New(snapped_clip.width())); | 225 v8::Number::New(isolate, snapped_clip.width())); |
226 result->Set(v8::String::NewFromUtf8(isolate, "height"), | 226 result->Set(v8::String::NewFromUtf8(isolate, "height"), |
227 v8::Number::New(snapped_clip.height())); | 227 v8::Number::New(isolate, snapped_clip.height())); |
228 result->Set(v8::String::NewFromUtf8(isolate, "data"), buffer.toV8Value()); | 228 result->Set(v8::String::NewFromUtf8(isolate, "data"), buffer.toV8Value()); |
229 | 229 |
230 args.GetReturnValue().Set(result); | 230 args.GetReturnValue().Set(result); |
231 } | 231 } |
232 | 232 |
233 static void GetOps(const v8::FunctionCallbackInfo<v8::Value>& args) { | 233 static void GetOps(const v8::FunctionCallbackInfo<v8::Value>& args) { |
234 if (args.Length() != 1) | 234 if (args.Length() != 1) |
235 return; | 235 return; |
236 | 236 |
237 v8::Isolate* isolate = args.GetIsolate(); | 237 v8::Isolate* isolate = args.GetIsolate(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 base::TimeDelta total_time = base::TimeTicks::HighResNow() - t0; | 293 base::TimeDelta total_time = base::TimeTicks::HighResNow() - t0; |
294 | 294 |
295 // Gather per-op timing info by drawing into a BenchmarkingCanvas. | 295 // Gather per-op timing info by drawing into a BenchmarkingCanvas. |
296 skia::BenchmarkingCanvas benchmarking_canvas(bounds.width(), | 296 skia::BenchmarkingCanvas benchmarking_canvas(bounds.width(), |
297 bounds.height()); | 297 bounds.height()); |
298 picture->Replay(&benchmarking_canvas); | 298 picture->Replay(&benchmarking_canvas); |
299 | 299 |
300 v8::Local<v8::Array> op_times = | 300 v8::Local<v8::Array> op_times = |
301 v8::Array::New(isolate, benchmarking_canvas.CommandCount()); | 301 v8::Array::New(isolate, benchmarking_canvas.CommandCount()); |
302 for (size_t i = 0; i < benchmarking_canvas.CommandCount(); ++i) | 302 for (size_t i = 0; i < benchmarking_canvas.CommandCount(); ++i) |
303 op_times->Set(i, v8::Number::New(benchmarking_canvas.GetTime(i))); | 303 op_times->Set(i, v8::Number::New(isolate, |
| 304 benchmarking_canvas.GetTime(i))); |
304 | 305 |
305 v8::Handle<v8::Object> result = v8::Object::New(isolate); | 306 v8::Handle<v8::Object> result = v8::Object::New(isolate); |
306 result->Set(v8::String::NewFromUtf8(isolate, "total_time"), | 307 result->Set(v8::String::NewFromUtf8(isolate, "total_time"), |
307 v8::Number::New(total_time.InMillisecondsF())); | 308 v8::Number::New(isolate, total_time.InMillisecondsF())); |
308 result->Set(v8::String::NewFromUtf8(isolate, "cmd_times"), op_times); | 309 result->Set(v8::String::NewFromUtf8(isolate, "cmd_times"), op_times); |
309 | 310 |
310 args.GetReturnValue().Set(result); | 311 args.GetReturnValue().Set(result); |
311 } | 312 } |
312 | 313 |
313 static void GetInfo(const v8::FunctionCallbackInfo<v8::Value>& args) { | 314 static void GetInfo(const v8::FunctionCallbackInfo<v8::Value>& args) { |
314 if (args.Length() != 1) | 315 if (args.Length() != 1) |
315 return; | 316 return; |
316 | 317 |
317 v8::Isolate* isolate = args.GetIsolate(); | 318 v8::Isolate* isolate = args.GetIsolate(); |
318 scoped_refptr<cc::Picture> picture = ParsePictureStr(isolate, args[0]); | 319 scoped_refptr<cc::Picture> picture = ParsePictureStr(isolate, args[0]); |
319 if (!picture.get()) | 320 if (!picture.get()) |
320 return; | 321 return; |
321 | 322 |
322 v8::Handle<v8::Object> result = v8::Object::New(isolate); | 323 v8::Handle<v8::Object> result = v8::Object::New(isolate); |
323 result->Set(v8::String::NewFromUtf8(isolate, "width"), | 324 result->Set(v8::String::NewFromUtf8(isolate, "width"), |
324 v8::Number::New(picture->LayerRect().width())); | 325 v8::Number::New(isolate, picture->LayerRect().width())); |
325 result->Set(v8::String::NewFromUtf8(isolate, "height"), | 326 result->Set(v8::String::NewFromUtf8(isolate, "height"), |
326 v8::Number::New(picture->LayerRect().height())); | 327 v8::Number::New(isolate, picture->LayerRect().height())); |
327 | 328 |
328 args.GetReturnValue().Set(result); | 329 args.GetReturnValue().Set(result); |
329 } | 330 } |
330 }; | 331 }; |
331 | 332 |
332 } // namespace | 333 } // namespace |
333 | 334 |
334 namespace content { | 335 namespace content { |
335 | 336 |
336 v8::Extension* SkiaBenchmarkingExtension::Get() { | 337 v8::Extension* SkiaBenchmarkingExtension::Get() { |
337 return new SkiaBenchmarkingWrapper(); | 338 return new SkiaBenchmarkingWrapper(); |
338 } | 339 } |
339 | 340 |
340 void SkiaBenchmarkingExtension::InitSkGraphics() { | 341 void SkiaBenchmarkingExtension::InitSkGraphics() { |
341 // Always call on the main render thread. | 342 // Always call on the main render thread. |
342 // Does not need to be thread-safe, as long as the above holds. | 343 // Does not need to be thread-safe, as long as the above holds. |
343 // FIXME: remove this after Skia updates SkGraphics::Init() to be | 344 // FIXME: remove this after Skia updates SkGraphics::Init() to be |
344 // thread-safe and idempotent. | 345 // thread-safe and idempotent. |
345 static bool skia_initialized = false; | 346 static bool skia_initialized = false; |
346 if (!skia_initialized) { | 347 if (!skia_initialized) { |
347 SkGraphics::Init(); | 348 SkGraphics::Init(); |
348 skia_initialized = true; | 349 skia_initialized = true; |
349 } | 350 } |
350 } | 351 } |
351 | 352 |
352 } // namespace content | 353 } // namespace content |
OLD | NEW |