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

Side by Side Diff: content/renderer/skia_benchmarking_extension.cc

Issue 184743002: don't create SkDevice directly, use SkBitmap or (better) SkCanvas::NewRaster factory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: revert changes to media unittests til we understand valgrind errors Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "cc/resources/picture.h" 11 #include "cc/resources/picture.h"
12 #include "content/public/renderer/v8_value_converter.h" 12 #include "content/public/renderer/v8_value_converter.h"
13 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
14 #include "gin/arguments.h" 14 #include "gin/arguments.h"
15 #include "gin/handle.h" 15 #include "gin/handle.h"
16 #include "gin/object_template_builder.h" 16 #include "gin/object_template_builder.h"
17 #include "skia/ext/benchmarking_canvas.h" 17 #include "skia/ext/benchmarking_canvas.h"
18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" 18 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
19 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h" 19 #include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
20 #include "third_party/WebKit/public/web/WebFrame.h" 20 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebKit.h" 21 #include "third_party/WebKit/public/web/WebKit.h"
22 #include "third_party/skia/include/core/SkBitmapDevice.h"
23 #include "third_party/skia/include/core/SkCanvas.h" 22 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "third_party/skia/include/core/SkColorPriv.h" 23 #include "third_party/skia/include/core/SkColorPriv.h"
25 #include "third_party/skia/include/core/SkGraphics.h" 24 #include "third_party/skia/include/core/SkGraphics.h"
26 #include "third_party/skia/include/core/SkStream.h" 25 #include "third_party/skia/include/core/SkStream.h"
27 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" 26 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h"
28 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h" 27 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h"
29 #include "ui/gfx/rect_conversions.h" 28 #include "ui/gfx/rect_conversions.h"
30 #include "ui/gfx/skia_util.h" 29 #include "ui/gfx/skia_util.h"
31 #include "v8/include/v8.h" 30 #include "v8/include/v8.h"
32 31
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 v8::Handle<v8::Value> picture_handle; 255 v8::Handle<v8::Value> picture_handle;
257 args->GetNext(&picture_handle); 256 args->GetNext(&picture_handle);
258 scoped_refptr<cc::Picture> picture = 257 scoped_refptr<cc::Picture> picture =
259 ParsePictureHash(isolate, picture_handle); 258 ParsePictureHash(isolate, picture_handle);
260 if (!picture.get()) 259 if (!picture.get())
261 return; 260 return;
262 261
263 gfx::Rect bounds = picture->LayerRect(); 262 gfx::Rect bounds = picture->LayerRect();
264 263
265 // Measure the total time by drawing straight into a bitmap-backed canvas. 264 // Measure the total time by drawing straight into a bitmap-backed canvas.
266 skia::RefPtr<SkBaseDevice> device = skia::AdoptRef(SkNEW_ARGS( 265 SkBitmap bitmap;
267 SkBitmapDevice, 266 bitmap.allocN32Pixels(bounds.width(), bounds.height());
268 (SkBitmap::kARGB_8888_Config, bounds.width(), bounds.height()))); 267 SkCanvas bitmap_canvas(bitmap);
269 SkCanvas bitmap_canvas(device.get());
270 bitmap_canvas.clear(SK_ColorTRANSPARENT); 268 bitmap_canvas.clear(SK_ColorTRANSPARENT);
271 base::TimeTicks t0 = base::TimeTicks::HighResNow(); 269 base::TimeTicks t0 = base::TimeTicks::HighResNow();
272 picture->Replay(&bitmap_canvas); 270 picture->Replay(&bitmap_canvas);
273 base::TimeDelta total_time = base::TimeTicks::HighResNow() - t0; 271 base::TimeDelta total_time = base::TimeTicks::HighResNow() - t0;
274 272
275 // Gather per-op timing info by drawing into a BenchmarkingCanvas. 273 // Gather per-op timing info by drawing into a BenchmarkingCanvas.
276 skia::BenchmarkingCanvas benchmarking_canvas(bounds.width(), bounds.height()); 274 skia::BenchmarkingCanvas benchmarking_canvas(bounds.width(), bounds.height());
277 picture->Replay(&benchmarking_canvas); 275 picture->Replay(&benchmarking_canvas);
278 276
279 v8::Local<v8::Array> op_times = 277 v8::Local<v8::Array> op_times =
(...skipping 23 matching lines...) Expand all
303 v8::Handle<v8::Object> result = v8::Object::New(isolate); 301 v8::Handle<v8::Object> result = v8::Object::New(isolate);
304 result->Set(v8::String::NewFromUtf8(isolate, "width"), 302 result->Set(v8::String::NewFromUtf8(isolate, "width"),
305 v8::Number::New(isolate, picture->LayerRect().width())); 303 v8::Number::New(isolate, picture->LayerRect().width()));
306 result->Set(v8::String::NewFromUtf8(isolate, "height"), 304 result->Set(v8::String::NewFromUtf8(isolate, "height"),
307 v8::Number::New(isolate, picture->LayerRect().height())); 305 v8::Number::New(isolate, picture->LayerRect().height()));
308 306
309 args->Return(result); 307 args->Return(result);
310 } 308 }
311 309
312 } // namespace content 310 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_browsertest.cc ('k') | skia/ext/benchmarking_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698