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/time/time.h" | 7 #include "base/time/time.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/resources/picture.h" | 10 #include "cc/resources/picture.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 " chrome = {};" | 49 " chrome = {};" |
50 "};" | 50 "};" |
51 "if (typeof(chrome.skiaBenchmarking) == 'undefined') {" | 51 "if (typeof(chrome.skiaBenchmarking) == 'undefined') {" |
52 " chrome.skiaBenchmarking = {};" | 52 " chrome.skiaBenchmarking = {};" |
53 "};" | 53 "};" |
54 "chrome.skiaBenchmarking.rasterize = function(picture, params) {" | 54 "chrome.skiaBenchmarking.rasterize = function(picture, params) {" |
55 " /* " | 55 " /* " |
56 " Rasterizes a Picture JSON-encoded by cc::Picture::AsValue()." | 56 " Rasterizes a Picture JSON-encoded by cc::Picture::AsValue()." |
57 " @param {Object} picture A json-encoded cc::Picture." | 57 " @param {Object} picture A json-encoded cc::Picture." |
58 " @param {" | 58 " @param {" |
59 " 'scale': {Number}," | 59 " 'scale': {Number}," |
60 " 'stop': {Number}," | 60 " 'stop': {Number}," |
61 " 'clip': [Number, Number, Number, Number]" | 61 " 'overdraw': {Boolean}," |
| 62 " 'clip': [Number, Number, Number, Number]" |
62 " } (optional) Rasterization parameters." | 63 " } (optional) Rasterization parameters." |
63 " @returns {" | 64 " @returns {" |
64 " 'width': {Number}," | 65 " 'width': {Number}," |
65 " 'height': {Number}," | 66 " 'height': {Number}," |
66 " 'data': {ArrayBuffer}" | 67 " 'data': {ArrayBuffer}" |
67 " }" | 68 " }" |
68 " @returns undefined if the arguments are invalid or the picture" | 69 " @returns undefined if the arguments are invalid or the picture" |
69 " version is not supported." | 70 " version is not supported." |
70 " */" | 71 " */" |
71 " native function Rasterize();" | 72 " native function Rasterize();" |
72 " return Rasterize(picture, params);" | 73 " return Rasterize(picture, params);" |
73 "};" | 74 "};" |
74 "chrome.skiaBenchmarking.getOps = function(picture) {" | 75 "chrome.skiaBenchmarking.getOps = function(picture) {" |
75 " /* " | 76 " /* " |
76 " Extracts the Skia draw commands from a JSON-encoded cc::Picture" | 77 " Extracts the Skia draw commands from a JSON-encoded cc::Picture" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 if (args.Length() < 1) | 114 if (args.Length() < 1) |
114 return; | 115 return; |
115 | 116 |
116 scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]); | 117 scoped_refptr<cc::Picture> picture = ParsePictureArg(args[0]); |
117 if (!picture.get()) | 118 if (!picture.get()) |
118 return; | 119 return; |
119 | 120 |
120 double scale = 1.0; | 121 double scale = 1.0; |
121 gfx::Rect clip_rect(picture->LayerRect()); | 122 gfx::Rect clip_rect(picture->LayerRect()); |
122 int stop_index = -1; | 123 int stop_index = -1; |
| 124 bool overdraw = false; |
123 | 125 |
124 if (args.Length() > 1) { | 126 if (args.Length() > 1) { |
125 scoped_ptr<content::V8ValueConverter> converter( | 127 scoped_ptr<content::V8ValueConverter> converter( |
126 content::V8ValueConverter::create()); | 128 content::V8ValueConverter::create()); |
127 scoped_ptr<base::Value> params_value( | 129 scoped_ptr<base::Value> params_value( |
128 converter->FromV8Value(args[1], v8::Context::GetCurrent())); | 130 converter->FromV8Value(args[1], v8::Context::GetCurrent())); |
129 | 131 |
130 const base::DictionaryValue* params_dict = NULL; | 132 const base::DictionaryValue* params_dict = NULL; |
131 if (params_value.get() && params_value->GetAsDictionary(¶ms_dict)) { | 133 if (params_value.get() && params_value->GetAsDictionary(¶ms_dict)) { |
132 params_dict->GetDouble("scale", &scale); | 134 params_dict->GetDouble("scale", &scale); |
133 params_dict->GetInteger("stop", &stop_index); | 135 params_dict->GetInteger("stop", &stop_index); |
| 136 params_dict->GetBoolean("overdraw", &overdraw); |
134 | 137 |
135 const base::Value* clip_value = NULL; | 138 const base::Value* clip_value = NULL; |
136 if (params_dict->Get("clip", &clip_value)) | 139 if (params_dict->Get("clip", &clip_value)) |
137 cc::MathUtil::FromValue(clip_value, &clip_rect); | 140 cc::MathUtil::FromValue(clip_value, &clip_rect); |
138 } | 141 } |
139 } | 142 } |
140 | 143 |
141 gfx::RectF clip(clip_rect); | 144 gfx::RectF clip(clip_rect); |
142 clip.Intersect(picture->LayerRect()); | 145 clip.Intersect(picture->LayerRect()); |
143 clip.Scale(scale); | 146 clip.Scale(scale); |
(...skipping 19 matching lines...) Expand all Loading... |
163 canvas.translate(picture->LayerRect().x(), | 166 canvas.translate(picture->LayerRect().x(), |
164 picture->LayerRect().y()); | 167 picture->LayerRect().y()); |
165 | 168 |
166 // First, build a debug canvas for the given picture. | 169 // First, build a debug canvas for the given picture. |
167 SkDebugCanvas debug_canvas(picture->LayerRect().width(), | 170 SkDebugCanvas debug_canvas(picture->LayerRect().width(), |
168 picture->LayerRect().height()); | 171 picture->LayerRect().height()); |
169 picture->Replay(&debug_canvas); | 172 picture->Replay(&debug_canvas); |
170 | 173 |
171 // Raster the requested command subset into the bitmap-backed canvas. | 174 // Raster the requested command subset into the bitmap-backed canvas. |
172 int last_index = debug_canvas.getSize() - 1; | 175 int last_index = debug_canvas.getSize() - 1; |
| 176 debug_canvas.setOverdrawViz(overdraw); |
173 debug_canvas.drawTo(&canvas, stop_index < 0 | 177 debug_canvas.drawTo(&canvas, stop_index < 0 |
174 ? last_index | 178 ? last_index |
175 : std::min(last_index, stop_index)); | 179 : std::min(last_index, stop_index)); |
176 | 180 |
177 WebKit::WebArrayBuffer buffer = | 181 WebKit::WebArrayBuffer buffer = |
178 WebKit::WebArrayBuffer::create(bitmap.getSize(), 1); | 182 WebKit::WebArrayBuffer::create(bitmap.getSize(), 1); |
179 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); | 183 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); |
180 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); | 184 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); |
181 // Swizzle from native Skia format to RGBA as we copy out. | 185 // Swizzle from native Skia format to RGBA as we copy out. |
182 for (size_t i = 0; i < bitmap.getSize(); i += 4) { | 186 for (size_t i = 0; i < bitmap.getSize(); i += 4) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // FIXME: remove this after Skia updates SkGraphics::Init() to be | 291 // FIXME: remove this after Skia updates SkGraphics::Init() to be |
288 // thread-safe and idempotent. | 292 // thread-safe and idempotent. |
289 static bool skia_initialized = false; | 293 static bool skia_initialized = false; |
290 if (!skia_initialized) { | 294 if (!skia_initialized) { |
291 SkGraphics::Init(); | 295 SkGraphics::Init(); |
292 skia_initialized = true; | 296 skia_initialized = true; |
293 } | 297 } |
294 } | 298 } |
295 | 299 |
296 } // namespace content | 300 } // namespace content |
OLD | NEW |