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

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

Issue 19266015: [SkiaBenchmarkingExtension] Add draw command timing info. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 7 years, 5 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/skia_benchmarking_extension.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "cc/base/math_util.h" 8 #include "cc/base/math_util.h"
9 #include "cc/resources/picture.h" 9 #include "cc/resources/picture.h"
10 #include "content/public/renderer/v8_value_converter.h" 10 #include "content/public/renderer/v8_value_converter.h"
11 #include "content/renderer/skia_benchmarking/skia_benchmarking_canvas.h"
11 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" 12 #include "third_party/WebKit/public/platform/WebArrayBuffer.h"
12 #include "third_party/WebKit/public/web/WebFrame.h" 13 #include "third_party/WebKit/public/web/WebFrame.h"
13 #include "third_party/skia/include/core/SkCanvas.h" 14 #include "third_party/skia/include/core/SkCanvas.h"
14 #include "third_party/skia/include/core/SkColorPriv.h" 15 #include "third_party/skia/include/core/SkColorPriv.h"
15 #include "third_party/skia/include/core/SkGraphics.h" 16 #include "third_party/skia/include/core/SkGraphics.h"
16 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" 17 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h"
17 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h" 18 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h"
18 #include "ui/gfx/rect_conversions.h" 19 #include "ui/gfx/rect_conversions.h"
19 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
20 #include "v8/include/v8.h" 21 #include "v8/include/v8.h"
21 22
22 using WebKit::WebFrame; 23 using WebKit::WebFrame;
24 using content::SkiaBenchmarkingCanvas;
23 25
24 namespace { 26 namespace {
25 27
26 const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking"; 28 const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking";
27 29
28 static scoped_refptr<cc::Picture> ParsePictureArg(v8::Handle<v8::Value> arg) { 30 static scoped_refptr<cc::Picture> ParsePictureArg(v8::Handle<v8::Value> arg) {
29 scoped_ptr<content::V8ValueConverter> converter( 31 scoped_ptr<content::V8ValueConverter> converter(
30 content::V8ValueConverter::create()); 32 content::V8ValueConverter::create());
31 33
32 v8::String::Value v8_picture(arg); 34 v8::String::Value v8_picture(arg);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 184 }
183 185
184 static void GetOps(const v8::FunctionCallbackInfo<v8::Value>& args) { 186 static void GetOps(const v8::FunctionCallbackInfo<v8::Value>& args) {
185 if (args.Length() != 1) 187 if (args.Length() != 1)
186 return; 188 return;
187 189
188 scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]); 190 scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]);
189 if (!picture.get()) 191 if (!picture.get())
190 return; 192 return;
191 193
192 gfx::Rect bounds = picture->LayerRect(); 194 SkiaBenchmarkingCanvas canvas(picture->LayerRect());
193 SkDebugCanvas canvas(bounds.width(), bounds.height());
194 picture->Replay(&canvas); 195 picture->Replay(&canvas);
195 196
196 v8::Local<v8::Array> result = v8::Array::New(canvas.getSize()); 197 v8::Local<v8::Array> result = v8::Array::New(canvas.CommandCount());
197 for (int i = 0; i < canvas.getSize(); ++i) { 198 for (size_t i = 0; i < canvas.CommandCount(); ++i) {
198 DrawType cmd_type = canvas.getDrawCommandAt(i)->getType(); 199 v8::Handle<v8::Object> v8_cmd = v8::Object::New();
199 v8::Handle<v8::Object> cmd = v8::Object::New(); 200 SkDrawCommand* cmd = canvas.GetCommand(i);
200 cmd->Set(v8::String::New("cmd_type"), v8::Integer::New(cmd_type)); 201 DCHECK(cmd);
201 cmd->Set(v8::String::New("cmd_string"), v8::String::New(
202 SkDrawCommand::GetCommandString(cmd_type)));
203 202
204 SkTDArray<SkString*>* info = canvas.getCommandInfo(i); 203 DrawType cmd_type = cmd->getType();
204 v8_cmd->Set(v8::String::New("cmd_type"), v8::Integer::New(cmd_type));
205 v8_cmd->Set(v8::String::New("cmd_string"),
206 v8::String::New(SkDrawCommand::GetCommandString(cmd_type)));
207 v8_cmd->Set(v8::String::New("cmd_time"),
208 v8::Number::New(canvas.GetTime(i)));
209
210 SkTDArray<SkString*>* info = cmd->Info();
205 DCHECK(info); 211 DCHECK(info);
206 212
207 v8::Local<v8::Array> v8_info = v8::Array::New(info->count()); 213 v8::Local<v8::Array> v8_info = v8::Array::New(info->count());
208 for (int j = 0; j < info->count(); ++j) { 214 for (int j = 0; j < info->count(); ++j) {
209 const SkString* info_str = (*info)[j]; 215 const SkString* info_str = (*info)[j];
210 DCHECK(info_str); 216 DCHECK(info_str);
211 v8_info->Set(j, v8::String::New(info_str->c_str())); 217 v8_info->Set(j, v8::String::New(info_str->c_str()));
212 } 218 }
219 v8_cmd->Set(v8::String::New("info"), v8_info);
213 220
214 cmd->Set(v8::String::New("info"), v8_info); 221 result->Set(i, v8_cmd);
215
216 result->Set(i, cmd);
217 } 222 }
218 223
219 args.GetReturnValue().Set(result); 224 args.GetReturnValue().Set(result);
220 } 225 }
221 }; 226 };
222 227
223 } // namespace 228 } // namespace
224 229
225 namespace content { 230 namespace content {
226 231
227 v8::Extension* SkiaBenchmarkingExtension::Get() { 232 v8::Extension* SkiaBenchmarkingExtension::Get() {
228 return new SkiaBenchmarkingWrapper(); 233 return new SkiaBenchmarkingWrapper();
229 } 234 }
230 235
231 void SkiaBenchmarkingExtension::InitSkGraphics() { 236 void SkiaBenchmarkingExtension::InitSkGraphics() {
232 // Always call on the main render thread. 237 // Always call on the main render thread.
233 // Does not need to be thread-safe, as long as the above holds. 238 // Does not need to be thread-safe, as long as the above holds.
234 // FIXME: remove this after Skia updates SkGraphics::Init() to be 239 // FIXME: remove this after Skia updates SkGraphics::Init() to be
235 // thread-safe and idempotent. 240 // thread-safe and idempotent.
236 static bool skia_initialized = false; 241 static bool skia_initialized = false;
237 if (!skia_initialized) { 242 if (!skia_initialized) {
238 SkGraphics::Init(); 243 SkGraphics::Init();
239 skia_initialized = true; 244 skia_initialized = true;
240 } 245 }
241 } 246 }
242 247
243 } // namespace content 248 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698