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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_win.cc

Issue 12881005: Allow CopyFromBackingStore to fallback to copying from the renderer side if the accelerated surface… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fallback to renderer side copy when backing store is not avilable too Created 7 years, 9 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
OLDNEW
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/browser/renderer_host/render_widget_host_view_win.h" 5 #include "content/browser/renderer_host/render_widget_host_view_win.h"
6 6
7 #include <InputScope.h> 7 #include <InputScope.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "content/common/view_messages.h" 43 #include "content/common/view_messages.h"
44 #include "content/public/browser/browser_thread.h" 44 #include "content/public/browser/browser_thread.h"
45 #include "content/public/browser/child_process_data.h" 45 #include "content/public/browser/child_process_data.h"
46 #include "content/public/browser/content_browser_client.h" 46 #include "content/public/browser/content_browser_client.h"
47 #include "content/public/browser/native_web_keyboard_event.h" 47 #include "content/public/browser/native_web_keyboard_event.h"
48 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/notification_service.h"
49 #include "content/public/browser/notification_types.h" 49 #include "content/public/browser/notification_types.h"
50 #include "content/public/common/content_switches.h" 50 #include "content/public/common/content_switches.h"
51 #include "content/public/common/page_zoom.h" 51 #include "content/public/common/page_zoom.h"
52 #include "content/public/common/process_type.h" 52 #include "content/public/common/process_type.h"
53 #include "media/base/video_util.h"
53 #include "skia/ext/skia_utils_win.h" 54 #include "skia/ext/skia_utils_win.h"
54 #include "third_party/skia/include/core/SkRegion.h" 55 #include "third_party/skia/include/core/SkRegion.h"
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
57 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h" 58 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h"
58 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact ory.h" 59 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact ory.h"
59 #include "ui/base/events/event.h" 60 #include "ui/base/events/event.h"
60 #include "ui/base/events/event_utils.h" 61 #include "ui/base/events/event_utils.h"
61 #include "ui/base/ime/composition_text.h" 62 #include "ui/base/ime/composition_text.h"
62 #include "ui/base/ime/win/tsf_input_scope.h" 63 #include "ui/base/ime/win/tsf_input_scope.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return pinch_allowed; 308 return pinch_allowed;
308 } 309 }
309 310
310 void GetScreenInfoForWindow(WebKit::WebScreenInfo* results, 311 void GetScreenInfoForWindow(WebKit::WebScreenInfo* results,
311 gfx::NativeViewId id) { 312 gfx::NativeViewId id) {
312 *results = WebKit::WebScreenInfoFactory::screenInfo( 313 *results = WebKit::WebScreenInfoFactory::screenInfo(
313 gfx::NativeViewFromId(id)); 314 gfx::NativeViewFromId(id));
314 results->deviceScaleFactor = ui::win::GetDeviceScaleFactor(); 315 results->deviceScaleFactor = ui::win::GetDeviceScaleFactor();
315 } 316 }
316 317
318 void CopySnapshotToVideoFrame(const scoped_refptr<media::VideoFrame>& target,
319 const gfx::Rect& region_in_frame,
320 const base::Callback<void(bool)>& callback,
321 bool succeed,
322 const SkBitmap& bitmap) {
323 if (!succeed) {
324 callback.Run(false);
325 return;
326 }
327
328 DCHECK(region_in_frame.size() == gfx::Size(bitmap.width(), bitmap.height()));
329 {
330 SkAutoLockPixels lock(bitmap);
331 media::CopyRGBToVideoFrame(
332 reinterpret_cast<const uint8*>(bitmap.getPixels()),
333 bitmap.rowBytes(),
334 region_in_frame,
335 target.get());
336 }
337 callback.Run(true);
338 }
339
317 } // namespace 340 } // namespace
318 341
319 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; 342 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND";
320 343
321 // Wrapper for maintaining touchstate associated with a WebTouchEvent. 344 // Wrapper for maintaining touchstate associated with a WebTouchEvent.
322 class WebTouchState { 345 class WebTouchState {
323 public: 346 public:
324 explicit WebTouchState(const RenderWidgetHostViewWin* window); 347 explicit WebTouchState(const RenderWidgetHostViewWin* window);
325 348
326 // Updates the current touchpoint state with the supplied touches. 349 // Updates the current touchpoint state with the supplied touches.
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 const gfx::Size& size) { 857 const gfx::Size& size) {
835 return new BackingStoreWin(render_widget_host_, size); 858 return new BackingStoreWin(render_widget_host_, size);
836 } 859 }
837 860
838 void RenderWidgetHostViewWin::CopyFromCompositingSurface( 861 void RenderWidgetHostViewWin::CopyFromCompositingSurface(
839 const gfx::Rect& src_subrect, 862 const gfx::Rect& src_subrect,
840 const gfx::Size& dst_size, 863 const gfx::Size& dst_size,
841 const base::Callback<void(bool, const SkBitmap&)>& callback) { 864 const base::Callback<void(bool, const SkBitmap&)>& callback) {
842 base::ScopedClosureRunner scoped_callback_runner( 865 base::ScopedClosureRunner scoped_callback_runner(
843 base::Bind(callback, false, SkBitmap())); 866 base::Bind(callback, false, SkBitmap()));
844 if (!accelerated_surface_.get())
845 return;
846
847 if (dst_size.IsEmpty() || src_subrect.IsEmpty()) 867 if (dst_size.IsEmpty() || src_subrect.IsEmpty())
848 return; 868 return;
849 869
850 scoped_callback_runner.Release(); 870 scoped_callback_runner.Release();
851 accelerated_surface_->AsyncCopyTo(src_subrect, dst_size, callback); 871
872 if (!accelerated_surface_.get()) {
873 // If we don't have an accelerated surface then copying from browser side
874 // will fail, so try a slower copy from renderer side instead.
875 render_widget_host_->GetSnapshotFromRenderer(
876 src_subrect, dst_size, callback);
877 } else {
878 accelerated_surface_->AsyncCopyTo(src_subrect, dst_size, callback);
879 }
852 } 880 }
853 881
854 void RenderWidgetHostViewWin::CopyFromCompositingSurfaceToVideoFrame( 882 void RenderWidgetHostViewWin::CopyFromCompositingSurfaceToVideoFrame(
855 const gfx::Rect& src_subrect, 883 const gfx::Rect& src_subrect,
856 const scoped_refptr<media::VideoFrame>& target, 884 const scoped_refptr<media::VideoFrame>& target,
857 const base::Callback<void(bool)>& callback) { 885 const base::Callback<void(bool)>& callback) {
858 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); 886 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false));
859 if (!accelerated_surface_.get())
860 return;
861 887
862 if (!target || target->format() != media::VideoFrame::YV12) 888 if (!target || target->format() != media::VideoFrame::YV12)
863 return; 889 return;
864 890
865 if (src_subrect.IsEmpty()) 891 if (src_subrect.IsEmpty())
866 return; 892 return;
867 893
868 scoped_callback_runner.Release(); 894 scoped_callback_runner.Release();
869 accelerated_surface_->AsyncCopyToVideoFrame(src_subrect, target, callback); 895
896 if (!accelerated_surface_.get()) {
897 // Compute the dest size we want after the letterboxing resize. Make the
898 // coordinates and sizes even because we letterbox in YUV space
899 // (see CopyRGBToVideoFrame). They need to be even for the UV samples to
900 // line up correctly.
901 gfx::Rect region_in_frame =
902 media::ComputeLetterboxRegion(gfx::Rect(target->coded_size()),
903 src_subrect.size());
904 region_in_frame = gfx::Rect(region_in_frame.x() & ~1,
905 region_in_frame.y() & ~1,
906 region_in_frame.width() & ~1,
907 region_in_frame.height() & ~1);
908
909 // If we don't have an accelerated surface then copying from browser side
910 // will fail, so try a slower copy from renderer side instead.
911 render_widget_host_->GetSnapshotFromRenderer(
912 src_subrect, region_in_frame.size(), base::Bind(
913 CopySnapshotToVideoFrame, target, region_in_frame, callback));
914 } else {
915 accelerated_surface_->AsyncCopyToVideoFrame(src_subrect, target, callback);
916 }
870 } 917 }
871 918
872 bool RenderWidgetHostViewWin::CanCopyToVideoFrame() const { 919 bool RenderWidgetHostViewWin::CanCopyToVideoFrame() const {
873 return accelerated_surface_.get() && render_widget_host_ && 920 return accelerated_surface_.get() && render_widget_host_ &&
874 render_widget_host_->is_accelerated_compositing_active(); 921 render_widget_host_->is_accelerated_compositing_active();
875 } 922 }
876 923
877 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { 924 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) {
878 RenderWidgetHostViewBase::SetBackground(background); 925 RenderWidgetHostViewBase::SetBackground(background);
879 render_widget_host_->SetBackground(background); 926 render_widget_host_->SetBackground(background);
(...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after
3102 return new RenderWidgetHostViewWin(widget); 3149 return new RenderWidgetHostViewWin(widget);
3103 } 3150 }
3104 3151
3105 // static 3152 // static
3106 void RenderWidgetHostViewPort::GetDefaultScreenInfo( 3153 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
3107 WebKit::WebScreenInfo* results) { 3154 WebKit::WebScreenInfo* results) {
3108 GetScreenInfoForWindow(results, 0); 3155 GetScreenInfoForWindow(results, 0);
3109 } 3156 }
3110 3157
3111 } // namespace content 3158 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698