| 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" |
| 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 "skia/ext/benchmarking_canvas.h" | 13 #include "skia/ext/benchmarking_canvas.h" |
| 14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 14 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
| 15 #include "third_party/WebKit/public/web/WebFrame.h" | 15 #include "third_party/WebKit/public/web/WebFrame.h" |
| 16 #include "third_party/skia/include/core/SkBitmapDevice.h" | 16 #include "third_party/skia/include/core/SkBitmapDevice.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkColorPriv.h" | 18 #include "third_party/skia/include/core/SkColorPriv.h" |
| 19 #include "third_party/skia/include/core/SkGraphics.h" | 19 #include "third_party/skia/include/core/SkGraphics.h" |
| 20 #include "third_party/skia/include/core/SkStream.h" | 20 #include "third_party/skia/include/core/SkStream.h" |
| 21 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" | 21 #include "third_party/skia/src/utils/debugger/SkDebugCanvas.h" |
| 22 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h" | 22 #include "third_party/skia/src/utils/debugger/SkDrawCommand.h" |
| 23 #include "ui/gfx/rect_conversions.h" | 23 #include "ui/gfx/rect_conversions.h" |
| 24 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 25 #include "v8/include/v8.h" | 25 #include "v8/include/v8.h" |
| 26 | 26 |
| 27 using WebKit::WebFrame; | 27 using blink::WebFrame; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking"; | 31 const char kSkiaBenchmarkingExtensionName[] = "v8/SkiaBenchmarking"; |
| 32 | 32 |
| 33 static scoped_ptr<base::Value> ParsePictureArg(v8::Handle<v8::Value> arg) { | 33 static scoped_ptr<base::Value> ParsePictureArg(v8::Handle<v8::Value> arg) { |
| 34 scoped_ptr<content::V8ValueConverter> converter( | 34 scoped_ptr<content::V8ValueConverter> converter( |
| 35 content::V8ValueConverter::create()); | 35 content::V8ValueConverter::create()); |
| 36 return scoped_ptr<base::Value>( | 36 return scoped_ptr<base::Value>( |
| 37 converter->FromV8Value(arg, v8::Context::GetCurrent())); | 37 converter->FromV8Value(arg, v8::Context::GetCurrent())); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 // Raster the requested command subset into the bitmap-backed canvas. | 196 // Raster the requested command subset into the bitmap-backed canvas. |
| 197 int last_index = debug_canvas.getSize() - 1; | 197 int last_index = debug_canvas.getSize() - 1; |
| 198 if (last_index >= 0) { | 198 if (last_index >= 0) { |
| 199 debug_canvas.setOverdrawViz(overdraw); | 199 debug_canvas.setOverdrawViz(overdraw); |
| 200 debug_canvas.drawTo(&canvas, stop_index < 0 | 200 debug_canvas.drawTo(&canvas, stop_index < 0 |
| 201 ? last_index | 201 ? last_index |
| 202 : std::min(last_index, stop_index)); | 202 : std::min(last_index, stop_index)); |
| 203 } | 203 } |
| 204 | 204 |
| 205 WebKit::WebArrayBuffer buffer = | 205 blink::WebArrayBuffer buffer = |
| 206 WebKit::WebArrayBuffer::create(bitmap.getSize(), 1); | 206 blink::WebArrayBuffer::create(bitmap.getSize(), 1); |
| 207 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); | 207 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); |
| 208 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); | 208 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); |
| 209 // Swizzle from native Skia format to RGBA as we copy out. | 209 // Swizzle from native Skia format to RGBA as we copy out. |
| 210 for (size_t i = 0; i < bitmap.getSize(); i += 4) { | 210 for (size_t i = 0; i < bitmap.getSize(); i += 4) { |
| 211 uint32 c = packed_pixels[i >> 2]; | 211 uint32 c = packed_pixels[i >> 2]; |
| 212 buffer_pixels[i] = SkGetPackedR32(c); | 212 buffer_pixels[i] = SkGetPackedR32(c); |
| 213 buffer_pixels[i + 1] = SkGetPackedG32(c); | 213 buffer_pixels[i + 1] = SkGetPackedG32(c); |
| 214 buffer_pixels[i + 2] = SkGetPackedB32(c); | 214 buffer_pixels[i + 2] = SkGetPackedB32(c); |
| 215 buffer_pixels[i + 3] = SkGetPackedA32(c); | 215 buffer_pixels[i + 3] = SkGetPackedA32(c); |
| 216 } | 216 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 // FIXME: remove this after Skia updates SkGraphics::Init() to be | 333 // FIXME: remove this after Skia updates SkGraphics::Init() to be |
| 334 // thread-safe and idempotent. | 334 // thread-safe and idempotent. |
| 335 static bool skia_initialized = false; | 335 static bool skia_initialized = false; |
| 336 if (!skia_initialized) { | 336 if (!skia_initialized) { |
| 337 SkGraphics::Init(); | 337 SkGraphics::Init(); |
| 338 skia_initialized = true; | 338 skia_initialized = true; |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 } // namespace content | 342 } // namespace content |
| OLD | NEW |