| 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/values.h" | 7 #include "base/values.h" |
| 8 #include "cc/resources/picture.h" | 8 #include "cc/resources/picture.h" |
| 9 #include "content/public/renderer/v8_value_converter.h" | 9 #include "content/public/renderer/v8_value_converter.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBuffer.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebArrayBuffer.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 SkBitmap bitmap; | 109 SkBitmap bitmap; |
| 110 bitmap.setConfig(SkBitmap::kARGB_8888_Config, snapped_clip.width(), | 110 bitmap.setConfig(SkBitmap::kARGB_8888_Config, snapped_clip.width(), |
| 111 snapped_clip.height()); | 111 snapped_clip.height()); |
| 112 if (!bitmap.allocPixels()) | 112 if (!bitmap.allocPixels()) |
| 113 return v8::Undefined(); | 113 return v8::Undefined(); |
| 114 | 114 |
| 115 bitmap.eraseARGB(0, 0, 0, 0); | 115 bitmap.eraseARGB(0, 0, 0, 0); |
| 116 SkCanvas canvas(bitmap); | 116 SkCanvas canvas(bitmap); |
| 117 canvas.translate(SkFloatToScalar(-clip.x()), | 117 canvas.translate(SkFloatToScalar(-clip.x()), |
| 118 SkFloatToScalar(-clip.y())); | 118 SkFloatToScalar(-clip.y())); |
| 119 picture->Raster(&canvas, NULL, snapped_clip, scale, true); | 119 picture->Raster(&canvas, NULL, snapped_clip, scale); |
| 120 | 120 |
| 121 WebKit::WebArrayBuffer buffer = | 121 WebKit::WebArrayBuffer buffer = |
| 122 WebKit::WebArrayBuffer::create(bitmap.getSize(), 1); | 122 WebKit::WebArrayBuffer::create(bitmap.getSize(), 1); |
| 123 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); | 123 uint32* packed_pixels = reinterpret_cast<uint32*>(bitmap.getPixels()); |
| 124 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); | 124 uint8* buffer_pixels = reinterpret_cast<uint8*>(buffer.data()); |
| 125 // Swizzle from native Skia format to RGBA as we copy out. | 125 // Swizzle from native Skia format to RGBA as we copy out. |
| 126 for (size_t i = 0; i < bitmap.getSize(); i += 4) { | 126 for (size_t i = 0; i < bitmap.getSize(); i += 4) { |
| 127 uint32 c = packed_pixels[i >> 2]; | 127 uint32 c = packed_pixels[i >> 2]; |
| 128 buffer_pixels[i] = SkGetPackedR32(c); | 128 buffer_pixels[i] = SkGetPackedR32(c); |
| 129 buffer_pixels[i + 1] = SkGetPackedG32(c); | 129 buffer_pixels[i + 1] = SkGetPackedG32(c); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 156 // FIXME: remove this after Skia updates SkGraphics::Init() to be | 156 // FIXME: remove this after Skia updates SkGraphics::Init() to be |
| 157 // thread-safe and idempotent. | 157 // thread-safe and idempotent. |
| 158 static bool skia_initialized = false; | 158 static bool skia_initialized = false; |
| 159 if (!skia_initialized) { | 159 if (!skia_initialized) { |
| 160 SkGraphics::Init(); | 160 SkGraphics::Init(); |
| 161 skia_initialized = true; | 161 skia_initialized = true; |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 } // namespace content | 165 } // namespace content |
| OLD | NEW |