| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gpu/gpu_benchmarking_extension.h" | 5 #include "content/renderer/gpu/gpu_benchmarking_extension.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "cc/layers/layer.h" | 14 #include "cc/layers/layer.h" |
| 15 #include "content/common/input/synthetic_gesture_params.h" | 15 #include "content/common/input/synthetic_gesture_params.h" |
| 16 #include "content/common/input/synthetic_pinch_gesture_params.h" | 16 #include "content/common/input/synthetic_pinch_gesture_params.h" |
| 17 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" | 17 #include "content/common/input/synthetic_smooth_scroll_gesture_params.h" |
| 18 #include "content/common/input/synthetic_tap_gesture_params.h" | 18 #include "content/common/input/synthetic_tap_gesture_params.h" |
| 19 #include "content/public/renderer/render_thread.h" | 19 #include "content/public/renderer/render_thread.h" |
| 20 #include "content/public/renderer/v8_value_converter.h" | 20 #include "content/public/renderer/v8_value_converter.h" |
| 21 #include "content/renderer/gpu/render_widget_compositor.h" | 21 #include "content/renderer/gpu/render_widget_compositor.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 22 #include "content/renderer/render_thread_impl.h" |
| 23 #include "content/renderer/render_view_impl.h" | 23 #include "content/renderer/render_view_impl.h" |
| 24 #include "content/renderer/skia_benchmarking_extension.h" | 24 #include "content/renderer/skia_benchmarking_extension.h" |
| 25 #include "third_party/WebKit/public/web/WebFrame.h" | |
| 26 #include "third_party/WebKit/public/web/WebImageCache.h" | 25 #include "third_party/WebKit/public/web/WebImageCache.h" |
| 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 27 #include "third_party/WebKit/public/web/WebView.h" | 27 #include "third_party/WebKit/public/web/WebView.h" |
| 28 #include "third_party/skia/include/core/SkData.h" | 28 #include "third_party/skia/include/core/SkData.h" |
| 29 #include "third_party/skia/include/core/SkGraphics.h" | 29 #include "third_party/skia/include/core/SkGraphics.h" |
| 30 #include "third_party/skia/include/core/SkPicture.h" | 30 #include "third_party/skia/include/core/SkPicture.h" |
| 31 #include "third_party/skia/include/core/SkPixelRef.h" | 31 #include "third_party/skia/include/core/SkPixelRef.h" |
| 32 #include "third_party/skia/include/core/SkStream.h" | 32 #include "third_party/skia/include/core/SkStream.h" |
| 33 #include "ui/gfx/codec/png_codec.h" | 33 #include "ui/gfx/codec/png_codec.h" |
| 34 #include "v8/include/v8.h" | 34 #include "v8/include/v8.h" |
| 35 | 35 |
| 36 using blink::WebCanvas; | 36 using blink::WebCanvas; |
| 37 using blink::WebFrame; | 37 using blink::WebLocalFrame; |
| 38 using blink::WebImageCache; | 38 using blink::WebImageCache; |
| 39 using blink::WebPrivatePtr; | 39 using blink::WebPrivatePtr; |
| 40 using blink::WebSize; | 40 using blink::WebSize; |
| 41 using blink::WebView; | 41 using blink::WebView; |
| 42 | 42 |
| 43 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; | 43 const char kGpuBenchmarkingExtensionName[] = "v8/GpuBenchmarking"; |
| 44 | 44 |
| 45 // offset parameter is deprecated/ignored, and will be remove from the | 45 // offset parameter is deprecated/ignored, and will be remove from the |
| 46 // signature in a future skia release. <reed@google.com> | 46 // signature in a future skia release. <reed@google.com> |
| 47 static SkData* EncodeBitmapToData(size_t* offset, const SkBitmap& bm) { | 47 static SkData* EncodeBitmapToData(size_t* offset, const SkBitmap& bm) { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 class GpuBenchmarkingContext { | 145 class GpuBenchmarkingContext { |
| 146 public: | 146 public: |
| 147 GpuBenchmarkingContext() | 147 GpuBenchmarkingContext() |
| 148 : web_frame_(NULL), | 148 : web_frame_(NULL), |
| 149 web_view_(NULL), | 149 web_view_(NULL), |
| 150 render_view_impl_(NULL), | 150 render_view_impl_(NULL), |
| 151 compositor_(NULL) {} | 151 compositor_(NULL) {} |
| 152 | 152 |
| 153 bool Init(bool init_compositor) { | 153 bool Init(bool init_compositor) { |
| 154 web_frame_ = WebFrame::frameForCurrentContext(); | 154 web_frame_ = WebLocalFrame::frameForCurrentContext(); |
| 155 if (!web_frame_) | 155 if (!web_frame_) |
| 156 return false; | 156 return false; |
| 157 | 157 |
| 158 web_view_ = web_frame_->view(); | 158 web_view_ = web_frame_->view(); |
| 159 if (!web_view_) { | 159 if (!web_view_) { |
| 160 web_frame_ = NULL; | 160 web_frame_ = NULL; |
| 161 return false; | 161 return false; |
| 162 } | 162 } |
| 163 | 163 |
| 164 render_view_impl_ = RenderViewImpl::FromWebView(web_view_); | 164 render_view_impl_ = RenderViewImpl::FromWebView(web_view_); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 if (!compositor_) { | 175 if (!compositor_) { |
| 176 web_frame_ = NULL; | 176 web_frame_ = NULL; |
| 177 web_view_ = NULL; | 177 web_view_ = NULL; |
| 178 render_view_impl_ = NULL; | 178 render_view_impl_ = NULL; |
| 179 return false; | 179 return false; |
| 180 } | 180 } |
| 181 | 181 |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 WebFrame* web_frame() const { | 185 WebLocalFrame* web_frame() const { |
| 186 DCHECK(web_frame_ != NULL); | 186 DCHECK(web_frame_ != NULL); |
| 187 return web_frame_; | 187 return web_frame_; |
| 188 } | 188 } |
| 189 WebView* web_view() const { | 189 WebView* web_view() const { |
| 190 DCHECK(web_view_ != NULL); | 190 DCHECK(web_view_ != NULL); |
| 191 return web_view_; | 191 return web_view_; |
| 192 } | 192 } |
| 193 RenderViewImpl* render_view_impl() const { | 193 RenderViewImpl* render_view_impl() const { |
| 194 DCHECK(render_view_impl_ != NULL); | 194 DCHECK(render_view_impl_ != NULL); |
| 195 return render_view_impl_; | 195 return render_view_impl_; |
| 196 } | 196 } |
| 197 RenderWidgetCompositor* compositor() const { | 197 RenderWidgetCompositor* compositor() const { |
| 198 DCHECK(compositor_ != NULL); | 198 DCHECK(compositor_ != NULL); |
| 199 return compositor_; | 199 return compositor_; |
| 200 } | 200 } |
| 201 | 201 |
| 202 private: | 202 private: |
| 203 WebFrame* web_frame_; | 203 WebLocalFrame* web_frame_; |
| 204 WebView* web_view_; | 204 WebView* web_view_; |
| 205 RenderViewImpl* render_view_impl_; | 205 RenderViewImpl* render_view_impl_; |
| 206 RenderWidgetCompositor* compositor_; | 206 RenderWidgetCompositor* compositor_; |
| 207 | 207 |
| 208 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); | 208 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarkingContext); |
| 209 }; | 209 }; |
| 210 | 210 |
| 211 } // namespace | 211 } // namespace |
| 212 | 212 |
| 213 class GpuBenchmarkingWrapper : public v8::Extension { | 213 class GpuBenchmarkingWrapper : public v8::Extension { |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 SkPictureSerializer serializer(dirpath); | 411 SkPictureSerializer serializer(dirpath); |
| 412 serializer.Serialize(root_layer); | 412 serializer.Serialize(root_layer); |
| 413 } | 413 } |
| 414 | 414 |
| 415 static void OnSyntheticGestureCompleted( | 415 static void OnSyntheticGestureCompleted( |
| 416 CallbackAndContext* callback_and_context) { | 416 CallbackAndContext* callback_and_context) { |
| 417 v8::Isolate* isolate = callback_and_context->isolate(); | 417 v8::Isolate* isolate = callback_and_context->isolate(); |
| 418 v8::HandleScope scope(isolate); | 418 v8::HandleScope scope(isolate); |
| 419 v8::Handle<v8::Context> context = callback_and_context->GetContext(); | 419 v8::Handle<v8::Context> context = callback_and_context->GetContext(); |
| 420 v8::Context::Scope context_scope(context); | 420 v8::Context::Scope context_scope(context); |
| 421 WebFrame* frame = WebFrame::frameForContext(context); | 421 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
| 422 if (frame) { | 422 if (frame) { |
| 423 frame->callFunctionEvenIfScriptDisabled( | 423 frame->callFunctionEvenIfScriptDisabled( |
| 424 callback_and_context->GetCallback(), | 424 callback_and_context->GetCallback(), |
| 425 v8::Object::New(isolate), | 425 v8::Object::New(isolate), |
| 426 0, | 426 0, |
| 427 NULL); | 427 NULL); |
| 428 } | 428 } |
| 429 } | 429 } |
| 430 | 430 |
| 431 static void SmoothScrollSendsTouch( | 431 static void SmoothScrollSendsTouch( |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 args.GetReturnValue().Set(true); | 733 args.GetReturnValue().Set(true); |
| 734 } | 734 } |
| 735 | 735 |
| 736 static void OnSnapshotCompleted(CallbackAndContext* callback_and_context, | 736 static void OnSnapshotCompleted(CallbackAndContext* callback_and_context, |
| 737 const gfx::Size& size, | 737 const gfx::Size& size, |
| 738 const std::vector<unsigned char>& png) { | 738 const std::vector<unsigned char>& png) { |
| 739 v8::Isolate* isolate = callback_and_context->isolate(); | 739 v8::Isolate* isolate = callback_and_context->isolate(); |
| 740 v8::HandleScope scope(isolate); | 740 v8::HandleScope scope(isolate); |
| 741 v8::Handle<v8::Context> context = callback_and_context->GetContext(); | 741 v8::Handle<v8::Context> context = callback_and_context->GetContext(); |
| 742 v8::Context::Scope context_scope(context); | 742 v8::Context::Scope context_scope(context); |
| 743 WebFrame* frame = WebFrame::frameForContext(context); | 743 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
| 744 if (frame) { | 744 if (frame) { |
| 745 | 745 |
| 746 v8::Handle<v8::Value> result; | 746 v8::Handle<v8::Value> result; |
| 747 | 747 |
| 748 if(!size.IsEmpty()) { | 748 if(!size.IsEmpty()) { |
| 749 v8::Handle<v8::Object> result_object; | 749 v8::Handle<v8::Object> result_object; |
| 750 result_object = v8::Object::New(isolate); | 750 result_object = v8::Object::New(isolate); |
| 751 | 751 |
| 752 result_object->Set(v8::String::NewFromUtf8(isolate, "width"), | 752 result_object->Set(v8::String::NewFromUtf8(isolate, "width"), |
| 753 v8::Number::New(isolate, size.width())); | 753 v8::Number::New(isolate, size.width())); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 WebImageCache::clear(); | 806 WebImageCache::clear(); |
| 807 } | 807 } |
| 808 | 808 |
| 809 static void OnMicroBenchmarkCompleted( | 809 static void OnMicroBenchmarkCompleted( |
| 810 CallbackAndContext* callback_and_context, | 810 CallbackAndContext* callback_and_context, |
| 811 scoped_ptr<base::Value> result) { | 811 scoped_ptr<base::Value> result) { |
| 812 v8::Isolate* isolate = callback_and_context->isolate(); | 812 v8::Isolate* isolate = callback_and_context->isolate(); |
| 813 v8::HandleScope scope(isolate); | 813 v8::HandleScope scope(isolate); |
| 814 v8::Handle<v8::Context> context = callback_and_context->GetContext(); | 814 v8::Handle<v8::Context> context = callback_and_context->GetContext(); |
| 815 v8::Context::Scope context_scope(context); | 815 v8::Context::Scope context_scope(context); |
| 816 WebFrame* frame = WebFrame::frameForContext(context); | 816 WebLocalFrame* frame = WebLocalFrame::frameForContext(context); |
| 817 if (frame) { | 817 if (frame) { |
| 818 scoped_ptr<V8ValueConverter> converter = | 818 scoped_ptr<V8ValueConverter> converter = |
| 819 make_scoped_ptr(V8ValueConverter::create()); | 819 make_scoped_ptr(V8ValueConverter::create()); |
| 820 v8::Handle<v8::Value> value = converter->ToV8Value(result.get(), context); | 820 v8::Handle<v8::Value> value = converter->ToV8Value(result.get(), context); |
| 821 v8::Handle<v8::Value> argv[] = { value }; | 821 v8::Handle<v8::Value> argv[] = { value }; |
| 822 | 822 |
| 823 frame->callFunctionEvenIfScriptDisabled( | 823 frame->callFunctionEvenIfScriptDisabled( |
| 824 callback_and_context->GetCallback(), | 824 callback_and_context->GetCallback(), |
| 825 v8::Object::New(isolate), | 825 v8::Object::New(isolate), |
| 826 1, | 826 1, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); | 870 GpuChannelHost* gpu_channel = RenderThreadImpl::current()->GetGpuChannel(); |
| 871 args.GetReturnValue().Set(!!gpu_channel); | 871 args.GetReturnValue().Set(!!gpu_channel); |
| 872 } | 872 } |
| 873 }; | 873 }; |
| 874 | 874 |
| 875 v8::Extension* GpuBenchmarkingExtension::Get() { | 875 v8::Extension* GpuBenchmarkingExtension::Get() { |
| 876 return new GpuBenchmarkingWrapper(); | 876 return new GpuBenchmarkingWrapper(); |
| 877 } | 877 } |
| 878 | 878 |
| 879 } // namespace content | 879 } // namespace content |
| OLD | NEW |