| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/renderer_host/render_widget_host_view_views.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/task.h" | 15 #include "base/task.h" |
| 16 #include "base/time.h" | 16 #include "base/time.h" |
| 17 #include "chrome/browser/renderer_host/backing_store_skia.h" |
| 17 #include "chrome/browser/renderer_host/backing_store_x.h" | 18 #include "chrome/browser/renderer_host/backing_store_x.h" |
| 18 #include "chrome/browser/renderer_host/render_widget_host.h" | 19 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 19 #include "chrome/common/native_web_keyboard_event.h" | 20 #include "chrome/common/native_web_keyboard_event.h" |
| 20 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 21 #include "chrome/common/result_codes.h" | 22 #include "chrome/common/result_codes.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/gtk/WebInputEventFact
ory.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 24 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" | 25 #include "ui/base/keycodes/keyboard_code_conversion_gtk.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/x/x11_util.h" | 27 #include "ui/base/x/x11_util.h" |
| 27 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 29 #include "ui/gfx/canvas_skia.h" |
| 28 #include "views/event.h" | 30 #include "views/event.h" |
| 29 #include "views/widget/widget.h" | 31 #include "views/widget/widget.h" |
| 30 #include "views/widget/widget_gtk.h" | 32 #include "views/widget/widget_gtk.h" |
| 31 | 33 |
| 32 static const int kMaxWindowWidth = 4000; | 34 static const int kMaxWindowWidth = 4000; |
| 33 static const int kMaxWindowHeight = 4000; | 35 static const int kMaxWindowHeight = 4000; |
| 34 static const char* kRenderWidgetHostViewKey = "__RENDER_WIDGET_HOST_VIEW__"; | 36 static const char kRenderWidgetHostViewKey[] = "__RENDER_WIDGET_HOST_VIEW__"; |
| 37 static const char kBackingStoreSkiaSwitch[] = "use-backing-store-skia"; |
| 35 | 38 |
| 36 using WebKit::WebInputEventFactory; | 39 using WebKit::WebInputEventFactory; |
| 37 using WebKit::WebMouseWheelEvent; | 40 using WebKit::WebMouseWheelEvent; |
| 38 using WebKit::WebTouchEvent; | 41 using WebKit::WebTouchEvent; |
| 39 | 42 |
| 40 namespace { | 43 namespace { |
| 41 | 44 |
| 45 bool UsingBackingStoreSkia() { |
| 46 static bool decided = false; |
| 47 static bool use_skia = false; |
| 48 if (!decided) { |
| 49 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 50 use_skia = (cmdline && cmdline->HasSwitch(kBackingStoreSkiaSwitch)); |
| 51 decided = true; |
| 52 } |
| 53 |
| 54 return use_skia; |
| 55 } |
| 56 |
| 42 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { | 57 int WebInputEventFlagsFromViewsEvent(const views::Event& event) { |
| 43 int modifiers = 0; | 58 int modifiers = 0; |
| 44 | 59 |
| 45 if (event.IsShiftDown()) | 60 if (event.IsShiftDown()) |
| 46 modifiers |= WebKit::WebInputEvent::ShiftKey; | 61 modifiers |= WebKit::WebInputEvent::ShiftKey; |
| 47 if (event.IsControlDown()) | 62 if (event.IsControlDown()) |
| 48 modifiers |= WebKit::WebInputEvent::ControlKey; | 63 modifiers |= WebKit::WebInputEvent::ControlKey; |
| 49 if (event.IsAltDown()) | 64 if (event.IsAltDown()) |
| 50 modifiers |= WebKit::WebInputEvent::AltKey; | 65 modifiers |= WebKit::WebInputEvent::AltKey; |
| 51 if (event.IsCapsLockDown()) | 66 if (event.IsCapsLockDown()) |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 336 |
| 322 bool RenderWidgetHostViewViews::IsPopup() { | 337 bool RenderWidgetHostViewViews::IsPopup() { |
| 323 return popup_type_ != WebKit::WebPopupTypeNone; | 338 return popup_type_ != WebKit::WebPopupTypeNone; |
| 324 } | 339 } |
| 325 | 340 |
| 326 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( | 341 BackingStore* RenderWidgetHostViewViews::AllocBackingStore( |
| 327 const gfx::Size& size) { | 342 const gfx::Size& size) { |
| 328 gfx::NativeView nview = GetInnerNativeView(); | 343 gfx::NativeView nview = GetInnerNativeView(); |
| 329 if (!nview) | 344 if (!nview) |
| 330 return NULL; | 345 return NULL; |
| 331 return new BackingStoreX(host_, size, | 346 |
| 332 ui::GetVisualFromGtkWidget(nview), | 347 if (UsingBackingStoreSkia()) { |
| 333 gtk_widget_get_visual(nview)->depth); | 348 return new BackingStoreSkia(host_, size); |
| 349 } else { |
| 350 return new BackingStoreX(host_, size, |
| 351 ui::GetVisualFromGtkWidget(nview), |
| 352 gtk_widget_get_visual(nview)->depth); |
| 353 } |
| 334 } | 354 } |
| 335 | 355 |
| 336 gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { | 356 gfx::NativeView RenderWidgetHostViewViews::GetInnerNativeView() const { |
| 337 // TODO(sad): Ideally this function should be equivalent to GetNativeView, and | 357 // TODO(sad): Ideally this function should be equivalent to GetNativeView, and |
| 338 // WidgetGtk-specific function call should not be necessary. | 358 // WidgetGtk-specific function call should not be necessary. |
| 339 views::WidgetGtk* widget = static_cast<views::WidgetGtk*>(GetWidget()); | 359 views::WidgetGtk* widget = static_cast<views::WidgetGtk*>(GetWidget()); |
| 340 return widget ? widget->window_contents() : NULL; | 360 return widget ? widget->window_contents() : NULL; |
| 341 } | 361 } |
| 342 | 362 |
| 343 gfx::NativeView RenderWidgetHostViewViews::GetNativeView() { | 363 gfx::NativeView RenderWidgetHostViewViews::GetNativeView() { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 373 GdkWindow* window = GetInnerNativeView()->window; | 393 GdkWindow* window = GetInnerNativeView()->window; |
| 374 DCHECK(!about_to_validate_and_paint_); | 394 DCHECK(!about_to_validate_and_paint_); |
| 375 | 395 |
| 376 // TODO(anicolao): get the damage somehow | 396 // TODO(anicolao): get the damage somehow |
| 377 // invalid_rect_ = damage_rect; | 397 // invalid_rect_ = damage_rect; |
| 378 invalid_rect_ = bounds(); | 398 invalid_rect_ = bounds(); |
| 379 gfx::Point origin; | 399 gfx::Point origin; |
| 380 ConvertPointToWidget(this, &origin); | 400 ConvertPointToWidget(this, &origin); |
| 381 | 401 |
| 382 about_to_validate_and_paint_ = true; | 402 about_to_validate_and_paint_ = true; |
| 383 BackingStoreX* backing_store = static_cast<BackingStoreX*>( | 403 BackingStore* backing_store = host_->GetBackingStore(true); |
| 384 host_->GetBackingStore(true)); | |
| 385 // Calling GetBackingStore maybe have changed |invalid_rect_|... | 404 // Calling GetBackingStore maybe have changed |invalid_rect_|... |
| 386 about_to_validate_and_paint_ = false; | 405 about_to_validate_and_paint_ = false; |
| 387 | 406 |
| 388 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); | 407 gfx::Rect paint_rect = gfx::Rect(0, 0, kMaxWindowWidth, kMaxWindowHeight); |
| 389 paint_rect = paint_rect.Intersect(invalid_rect_); | 408 paint_rect = paint_rect.Intersect(invalid_rect_); |
| 390 | 409 |
| 391 if (backing_store) { | 410 if (backing_store) { |
| 392 // Only render the widget if it is attached to a window; there's a short | 411 // Only render the widget if it is attached to a window; there's a short |
| 393 // period where this object isn't attached to a window but hasn't been | 412 // period where this object isn't attached to a window but hasn't been |
| 394 // Destroy()ed yet and it receives paint messages... | 413 // Destroy()ed yet and it receives paint messages... |
| 395 if (window) { | 414 if (window) { |
| 396 if (!visually_deemphasized_) { | 415 if (!visually_deemphasized_) { |
| 397 // In the common case, use XCopyArea. We don't draw more than once, so | 416 // In the common case, use XCopyArea. We don't draw more than once, so |
| 398 // we don't need to double buffer. | 417 // we don't need to double buffer. |
| 399 backing_store->XShowRect(origin, | 418 |
| 400 paint_rect, ui::GetX11WindowFromGdkWindow(window)); | 419 if (UsingBackingStoreSkia()) { |
| 401 } else { | 420 static_cast<BackingStoreSkia*>(backing_store)->SkiaShowRect( |
| 421 gfx::Point(paint_rect.x(), paint_rect.y()), canvas); |
| 422 } else { |
| 423 static_cast<BackingStoreX*>(backing_store)->XShowRect(origin, |
| 424 paint_rect, ui::GetX11WindowFromGdkWindow(window)); |
| 425 } |
| 426 } else if (!UsingBackingStoreSkia()) { |
| 402 // If the grey blend is showing, we make two drawing calls. Use double | 427 // If the grey blend is showing, we make two drawing calls. Use double |
| 403 // buffering to prevent flicker. Use CairoShowRect because XShowRect | 428 // buffering to prevent flicker. Use CairoShowRect because XShowRect |
| 404 // shortcuts GDK's double buffering. | 429 // shortcuts GDK's double buffering. |
| 405 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), | 430 GdkRectangle rect = { paint_rect.x(), paint_rect.y(), |
| 406 paint_rect.width(), paint_rect.height() }; | 431 paint_rect.width(), paint_rect.height() }; |
| 407 gdk_window_begin_paint_rect(window, &rect); | 432 gdk_window_begin_paint_rect(window, &rect); |
| 408 | 433 |
| 409 backing_store->CairoShowRect(paint_rect, GDK_DRAWABLE(window)); | 434 static_cast<BackingStoreX*>(backing_store)->CairoShowRect( |
| 435 paint_rect, GDK_DRAWABLE(window)); |
| 410 | 436 |
| 411 cairo_t* cr = gdk_cairo_create(window); | 437 cairo_t* cr = gdk_cairo_create(window); |
| 412 gdk_cairo_rectangle(cr, &rect); | 438 gdk_cairo_rectangle(cr, &rect); |
| 413 cairo_set_source_rgba(cr, 0, 0, 0, 0.7); | 439 cairo_set_source_rgba(cr, 0, 0, 0, 0.7); |
| 414 cairo_fill(cr); | 440 cairo_fill(cr); |
| 415 cairo_destroy(cr); | 441 cairo_destroy(cr); |
| 416 | 442 |
| 417 gdk_window_end_paint(window); | 443 gdk_window_end_paint(window); |
| 444 } else { |
| 445 // TODO(sad) |
| 446 NOTIMPLEMENTED(); |
| 418 } | 447 } |
| 419 } | 448 } |
| 420 if (!whiteout_start_time_.is_null()) { | 449 if (!whiteout_start_time_.is_null()) { |
| 421 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 450 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
| 422 whiteout_start_time_; | 451 whiteout_start_time_; |
| 423 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 452 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
| 424 | 453 |
| 425 // Reset the start time to 0 so that we start recording again the next | 454 // Reset the start time to 0 so that we start recording again the next |
| 426 // time the backing store is NULL... | 455 // time the backing store is NULL... |
| 427 whiteout_start_time_ = base::TimeTicks(); | 456 whiteout_start_time_ = base::TimeTicks(); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 } | 797 } |
| 769 | 798 |
| 770 // static | 799 // static |
| 771 RenderWidgetHostView* | 800 RenderWidgetHostView* |
| 772 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( | 801 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( |
| 773 gfx::NativeView widget) { | 802 gfx::NativeView widget) { |
| 774 gpointer user_data = g_object_get_data(G_OBJECT(widget), | 803 gpointer user_data = g_object_get_data(G_OBJECT(widget), |
| 775 kRenderWidgetHostViewKey); | 804 kRenderWidgetHostViewKey); |
| 776 return reinterpret_cast<RenderWidgetHostView*>(user_data); | 805 return reinterpret_cast<RenderWidgetHostView*>(user_data); |
| 777 } | 806 } |
| OLD | NEW |