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/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" | 32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" | 33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
35 #include "third_party/skia/include/core/SkShader.h" | 35 #include "third_party/skia/include/core/SkShader.h" |
36 #include "third_party/skia/include/effects/SkTableColorFilter.h" | |
37 #include "ui/gfx/point.h" | 36 #include "ui/gfx/point.h" |
38 #include "ui/gfx/size.h" | 37 #include "ui/gfx/size.h" |
39 #include "ui/gfx/skia_util.h" | 38 #include "ui/gfx/skia_util.h" |
40 #include "ui/gl/gl_switches.h" | 39 #include "ui/gl/gl_switches.h" |
41 #include "ui/surface/transport_dib.h" | 40 #include "ui/surface/transport_dib.h" |
42 #include "webkit/glue/webkit_glue.h" | 41 #include "webkit/glue/webkit_glue.h" |
43 #include "webkit/plugins/npapi/webplugin.h" | 42 #include "webkit/plugins/npapi/webplugin.h" |
44 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 43 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
45 | 44 |
46 #if defined(OS_POSIX) | 45 #if defined(OS_POSIX) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 input_method_is_active_(false), | 99 input_method_is_active_(false), |
101 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 100 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
102 can_compose_inline_(true), | 101 can_compose_inline_(true), |
103 popup_type_(popup_type), | 102 popup_type_(popup_type), |
104 pending_window_rect_count_(0), | 103 pending_window_rect_count_(0), |
105 suppress_next_char_events_(false), | 104 suppress_next_char_events_(false), |
106 is_accelerated_compositing_active_(false), | 105 is_accelerated_compositing_active_(false), |
107 animation_update_pending_(false), | 106 animation_update_pending_(false), |
108 invalidation_task_posted_(false), | 107 invalidation_task_posted_(false), |
109 screen_info_(screen_info), | 108 screen_info_(screen_info), |
110 device_scale_factor_(1), | 109 device_scale_factor_(1) { |
111 invert_(false) { | |
112 if (!swapped_out) | 110 if (!swapped_out) |
113 RenderProcess::current()->AddRefProcess(); | 111 RenderProcess::current()->AddRefProcess(); |
114 DCHECK(RenderThread::Get()); | 112 DCHECK(RenderThread::Get()); |
115 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( | 113 has_disable_gpu_vsync_switch_ = CommandLine::ForCurrentProcess()->HasSwitch( |
116 switches::kDisableGpuVsync); | 114 switches::kDisableGpuVsync); |
117 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) | 115 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) |
118 device_scale_factor_ = std::max(1, screen_info.verticalDPI / kStandardDPI); | 116 device_scale_factor_ = std::max(1, screen_info.verticalDPI / kStandardDPI); |
119 #endif | 117 #endif |
120 } | 118 } |
121 | 119 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) | 230 IPC_MESSAGE_HANDLER(ViewMsg_HandleInputEvent, OnHandleInputEvent) |
233 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) | 231 IPC_MESSAGE_HANDLER(ViewMsg_MouseCaptureLost, OnMouseCaptureLost) |
234 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) | 232 IPC_MESSAGE_HANDLER(ViewMsg_SetFocus, OnSetFocus) |
235 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) | 233 IPC_MESSAGE_HANDLER(ViewMsg_SetInputMethodActive, OnSetInputMethodActive) |
236 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) | 234 IPC_MESSAGE_HANDLER(ViewMsg_ImeSetComposition, OnImeSetComposition) |
237 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) | 235 IPC_MESSAGE_HANDLER(ViewMsg_ImeConfirmComposition, OnImeConfirmComposition) |
238 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) | 236 IPC_MESSAGE_HANDLER(ViewMsg_PaintAtSize, OnMsgPaintAtSize) |
239 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) | 237 IPC_MESSAGE_HANDLER(ViewMsg_Repaint, OnMsgRepaint) |
240 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) | 238 IPC_MESSAGE_HANDLER(ViewMsg_SetTextDirection, OnSetTextDirection) |
241 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) | 239 IPC_MESSAGE_HANDLER(ViewMsg_Move_ACK, OnRequestMoveAck) |
242 IPC_MESSAGE_HANDLER(ViewMsg_InvertWebContent, OnInvertWebContent) | |
243 IPC_MESSAGE_UNHANDLED(handled = false) | 240 IPC_MESSAGE_UNHANDLED(handled = false) |
244 IPC_END_MESSAGE_MAP() | 241 IPC_END_MESSAGE_MAP() |
245 return handled; | 242 return handled; |
246 } | 243 } |
247 | 244 |
248 bool RenderWidget::Send(IPC::Message* message) { | 245 bool RenderWidget::Send(IPC::Message* message) { |
249 // Don't send any messages after the browser has told us to close, and filter | 246 // Don't send any messages after the browser has told us to close, and filter |
250 // most outgoing messages while swapped out. | 247 // most outgoing messages while swapped out. |
251 if ((is_swapped_out_ && | 248 if ((is_swapped_out_ && |
252 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) || | 249 !content::SwappedOutMessages::CanSendWhileSwappedOut(message)) || |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 const gfx::Point& canvas_origin, | 621 const gfx::Point& canvas_origin, |
625 skia::PlatformCanvas* canvas) { | 622 skia::PlatformCanvas* canvas) { |
626 TRACE_EVENT2("renderer", "PaintRect", | 623 TRACE_EVENT2("renderer", "PaintRect", |
627 "width", rect.width(), "height", rect.height()); | 624 "width", rect.width(), "height", rect.height()); |
628 canvas->save(); | 625 canvas->save(); |
629 | 626 |
630 // Bring the canvas into the coordinate system of the paint rect. | 627 // Bring the canvas into the coordinate system of the paint rect. |
631 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), | 628 canvas->translate(static_cast<SkScalar>(-canvas_origin.x()), |
632 static_cast<SkScalar>(-canvas_origin.y())); | 629 static_cast<SkScalar>(-canvas_origin.y())); |
633 | 630 |
634 if (invert_) { | |
635 // Draw everything to a temporary bitmap and then apply an | |
636 // inverting color map to the result. This is balanced by an extra | |
637 // call to canvas->restore(), below. | |
638 DCHECK(invert_paint_.get()); | |
639 SkRect bounds(gfx::RectToSkRect(rect)); | |
640 canvas->saveLayer(&bounds, invert_paint_.get()); | |
641 } | |
642 | |
643 // If there is a custom background, tile it. | 631 // If there is a custom background, tile it. |
644 if (!background_.empty()) { | 632 if (!background_.empty()) { |
645 SkPaint paint; | 633 SkPaint paint; |
646 SkShader* shader = SkShader::CreateBitmapShader(background_, | 634 SkShader* shader = SkShader::CreateBitmapShader(background_, |
647 SkShader::kRepeat_TileMode, | 635 SkShader::kRepeat_TileMode, |
648 SkShader::kRepeat_TileMode); | 636 SkShader::kRepeat_TileMode); |
649 paint.setShader(shader)->unref(); | 637 paint.setShader(shader)->unref(); |
650 | 638 |
651 // Use kSrc_Mode to handle background_ transparency properly. | 639 // Use kSrc_Mode to handle background_ transparency properly. |
652 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 640 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas), | 678 optimized_instance->Paint(webkit_glue::ToWebCanvas(canvas), |
691 optimized_copy_location, rect); | 679 optimized_copy_location, rect); |
692 } else { | 680 } else { |
693 // Normal painting case. | 681 // Normal painting case. |
694 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); | 682 webwidget_->paint(webkit_glue::ToWebCanvas(canvas), rect); |
695 | 683 |
696 // Flush to underlying bitmap. TODO(darin): is this needed? | 684 // Flush to underlying bitmap. TODO(darin): is this needed? |
697 skia::GetTopDevice(*canvas)->accessBitmap(false); | 685 skia::GetTopDevice(*canvas)->accessBitmap(false); |
698 } | 686 } |
699 | 687 |
700 if (invert_) | |
701 canvas->restore(); | |
702 | |
703 PaintDebugBorder(rect, canvas); | 688 PaintDebugBorder(rect, canvas); |
704 canvas->restore(); | 689 canvas->restore(); |
705 } | 690 } |
706 | 691 |
707 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, | 692 void RenderWidget::PaintDebugBorder(const gfx::Rect& rect, |
708 skia::PlatformCanvas* canvas) { | 693 skia::PlatformCanvas* canvas) { |
709 static bool kPaintBorder = | 694 static bool kPaintBorder = |
710 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); | 695 CommandLine::ForCurrentProcess()->HasSwitch(switches::kShowPaintRects); |
711 if (!kPaintBorder) | 696 if (!kPaintBorder) |
712 return; | 697 return; |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 didInvalidateRect(repaint_rect); | 1472 didInvalidateRect(repaint_rect); |
1488 } | 1473 } |
1489 } | 1474 } |
1490 | 1475 |
1491 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { | 1476 void RenderWidget::OnSetTextDirection(WebTextDirection direction) { |
1492 if (!webwidget_) | 1477 if (!webwidget_) |
1493 return; | 1478 return; |
1494 webwidget_->setTextDirection(direction); | 1479 webwidget_->setTextDirection(direction); |
1495 } | 1480 } |
1496 | 1481 |
1497 void RenderWidget::OnInvertWebContent(bool invert) { | |
1498 if (invert_ == invert) | |
1499 return; | |
1500 | |
1501 invert_ = invert; | |
1502 | |
1503 if (invert_ && !invert_paint_.get()) { | |
1504 // Gamma-aware color inversion: each source pixel value x is normally | |
1505 // displayed on a computer monitor with a gamma correction x^gamma, | |
1506 // where gamma is typically in the range 1.8...2.2. By approximating | |
1507 // gamma as exactly 2, the formula to invert one value is sqrt(1 - x^2). | |
1508 uint8_t table[256]; | |
1509 for (unsigned int i = 0; i < 256; i++) { | |
1510 double value = i / 255.0; | |
1511 value = sqrt(1 - (value * value)); | |
1512 table[i] = static_cast<uint8_t>(255 * value); | |
1513 } | |
1514 | |
1515 // Create a Skia Paint with this inverting color map. | |
1516 invert_paint_.reset(new SkPaint()); | |
1517 invert_paint_->setStyle(SkPaint::kFill_Style); | |
1518 invert_paint_->setColor(SK_ColorBLACK); | |
1519 SkColorFilter* filter = SkTableColorFilter::CreateARGB( | |
1520 NULL, table, table, table); | |
1521 invert_paint_->setColorFilter(filter); | |
1522 filter->unref(); | |
1523 } | |
1524 | |
1525 OnMsgRepaint(size_); | |
1526 } | |
1527 | |
1528 webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( | 1482 webkit::ppapi::PluginInstance* RenderWidget::GetBitmapForOptimizedPluginPaint( |
1529 const gfx::Rect& paint_bounds, | 1483 const gfx::Rect& paint_bounds, |
1530 TransportDIB** dib, | 1484 TransportDIB** dib, |
1531 gfx::Rect* location, | 1485 gfx::Rect* location, |
1532 gfx::Rect* clip) { | 1486 gfx::Rect* clip) { |
1533 // Bare RenderWidgets don't support optimized plugin painting. | 1487 // Bare RenderWidgets don't support optimized plugin painting. |
1534 return NULL; | 1488 return NULL; |
1535 } | 1489 } |
1536 | 1490 |
1537 gfx::Point RenderWidget::GetScrollOffset() { | 1491 gfx::Point RenderWidget::GetScrollOffset() { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1745 } | 1699 } |
1746 } | 1700 } |
1747 | 1701 |
1748 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 1702 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
1749 return false; | 1703 return false; |
1750 } | 1704 } |
1751 | 1705 |
1752 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 1706 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
1753 return false; | 1707 return false; |
1754 } | 1708 } |
OLD | NEW |