| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
| 8 #include "base/timer.h" | 8 #include "base/timer.h" |
| 9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
| 10 #include "content/browser/renderer_host/backing_store.h" | 10 #include "content/browser/renderer_host/backing_store.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 void set_update_msg_reply_flags(int flags) { | 59 void set_update_msg_reply_flags(int flags) { |
| 60 update_msg_reply_flags_ = flags; | 60 update_msg_reply_flags_ = flags; |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Fills the given update parameters with resonable default values. | 63 // Fills the given update parameters with resonable default values. |
| 64 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); | 64 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); |
| 65 | 65 |
| 66 virtual bool HasConnection() const { return true; } | 66 virtual bool HasConnection() const { return true; } |
| 67 | 67 |
| 68 protected: | 68 protected: |
| 69 virtual bool WaitForUpdateMsg(int render_widget_id, | 69 virtual bool WaitForBackingStoreMsg(int render_widget_id, |
| 70 const base::TimeDelta& max_delay, | 70 const base::TimeDelta& max_delay, |
| 71 IPC::Message* msg); | 71 IPC::Message* msg); |
| 72 | 72 |
| 73 TransportDIB* current_update_buf_; | 73 TransportDIB* current_update_buf_; |
| 74 | 74 |
| 75 // Set to true when WaitForUpdateMsg should return a successful update message | 75 // Set to true when WaitForBackingStoreMsg should return a successful update |
| 76 // reply. False implies timeout. | 76 // message reply. False implies timeout. |
| 77 bool update_msg_should_reply_; | 77 bool update_msg_should_reply_; |
| 78 | 78 |
| 79 // Indicates the flags that should be sent with a the repaint request. This | 79 // Indicates the flags that should be sent with a the repaint request. This |
| 80 // only has an effect when update_msg_should_reply_ is true. | 80 // only has an effect when update_msg_should_reply_ is true. |
| 81 int update_msg_reply_flags_; | 81 int update_msg_reply_flags_; |
| 82 | 82 |
| 83 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); | 83 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 void RenderWidgetHostProcess::InitUpdateRectParams( | 86 void RenderWidgetHostProcess::InitUpdateRectParams( |
| 87 ViewHostMsg_UpdateRect_Params* params) { | 87 ViewHostMsg_UpdateRect_Params* params) { |
| 88 // Create the shared backing store. | 88 // Create the shared backing store. |
| 89 const int w = 100, h = 100; | 89 const int w = 100, h = 100; |
| 90 const size_t pixel_size = w * h * 4; | 90 const size_t pixel_size = w * h * 4; |
| 91 | 91 |
| 92 if (!current_update_buf_) | 92 if (!current_update_buf_) |
| 93 current_update_buf_ = TransportDIB::Create(pixel_size, 0); | 93 current_update_buf_ = TransportDIB::Create(pixel_size, 0); |
| 94 params->bitmap = current_update_buf_->id(); | 94 params->bitmap = current_update_buf_->id(); |
| 95 params->bitmap_rect = gfx::Rect(0, 0, w, h); | 95 params->bitmap_rect = gfx::Rect(0, 0, w, h); |
| 96 params->dx = 0; | 96 params->dx = 0; |
| 97 params->dy = 0; | 97 params->dy = 0; |
| 98 params->copy_rects.push_back(params->bitmap_rect); | 98 params->copy_rects.push_back(params->bitmap_rect); |
| 99 params->view_size = gfx::Size(w, h); | 99 params->view_size = gfx::Size(w, h); |
| 100 params->flags = update_msg_reply_flags_; | 100 params->flags = update_msg_reply_flags_; |
| 101 params->needs_ack = true; | 101 params->needs_ack = true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool RenderWidgetHostProcess::WaitForUpdateMsg(int render_widget_id, | 104 bool RenderWidgetHostProcess::WaitForBackingStoreMsg( |
| 105 const base::TimeDelta& max_delay, | 105 int render_widget_id, |
| 106 IPC::Message* msg) { | 106 const base::TimeDelta& max_delay, |
| 107 IPC::Message* msg) { |
| 107 if (!update_msg_should_reply_) | 108 if (!update_msg_should_reply_) |
| 108 return false; | 109 return false; |
| 109 | 110 |
| 110 // Construct a fake update reply. | 111 // Construct a fake update reply. |
| 111 ViewHostMsg_UpdateRect_Params params; | 112 ViewHostMsg_UpdateRect_Params params; |
| 112 InitUpdateRectParams(¶ms); | 113 InitUpdateRectParams(¶ms); |
| 113 | 114 |
| 114 ViewHostMsg_UpdateRect message(render_widget_id, params); | 115 ViewHostMsg_UpdateRect message(render_widget_id, params); |
| 115 *msg = message; | 116 *msg = message; |
| 116 return true; | 117 return true; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 #endif | 502 #endif |
| 502 | 503 |
| 503 // TODO(aa): It would be nice to factor out the painting logic so that we | 504 // TODO(aa): It would be nice to factor out the painting logic so that we |
| 504 // could test that, but it appears that would mean painting everything twice | 505 // could test that, but it appears that would mean painting everything twice |
| 505 // since windows HDC structures are opaque. | 506 // since windows HDC structures are opaque. |
| 506 } | 507 } |
| 507 | 508 |
| 508 // Tests getting the backing store with the renderer not setting repaint ack | 509 // Tests getting the backing store with the renderer not setting repaint ack |
| 509 // flags. | 510 // flags. |
| 510 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) { | 511 TEST_F(RenderWidgetHostTest, GetBackingStore_NoRepaintAck) { |
| 512 // First set the view size to match what the renderer is rendering. |
| 513 ViewHostMsg_UpdateRect_Params params; |
| 514 process_->InitUpdateRectParams(¶ms); |
| 515 view_->set_bounds(gfx::Rect(params.view_size)); |
| 516 |
| 511 // We don't currently have a backing store, and if the renderer doesn't send | 517 // We don't currently have a backing store, and if the renderer doesn't send |
| 512 // one in time, we should get nothing. | 518 // one in time, we should get nothing. |
| 513 process_->set_update_msg_should_reply(false); | 519 process_->set_update_msg_should_reply(false); |
| 514 BackingStore* backing = host_->GetBackingStore(true); | 520 BackingStore* backing = host_->GetBackingStore(true); |
| 515 EXPECT_FALSE(backing); | 521 EXPECT_FALSE(backing); |
| 516 // The widget host should have sent a request for a repaint, and there should | 522 // The widget host should have sent a request for a repaint, and there should |
| 517 // be no paint ACK. | 523 // be no paint ACK. |
| 518 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); | 524 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); |
| 519 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( | 525 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching( |
| 520 ViewMsg_UpdateRect_ACK::ID)); | 526 ViewMsg_UpdateRect_ACK::ID)); |
| 521 | 527 |
| 522 // Allowing the renderer to reply in time should give is a backing store. | 528 // Allowing the renderer to reply in time should give is a backing store. |
| 523 process_->sink().ClearMessages(); | 529 process_->sink().ClearMessages(); |
| 524 process_->set_update_msg_should_reply(true); | 530 process_->set_update_msg_should_reply(true); |
| 525 process_->set_update_msg_reply_flags(0); | 531 process_->set_update_msg_reply_flags(0); |
| 526 backing = host_->GetBackingStore(true); | 532 backing = host_->GetBackingStore(true); |
| 527 EXPECT_TRUE(backing); | 533 EXPECT_TRUE(backing); |
| 528 // The widget host should NOT have sent a request for a repaint, since there | 534 // The widget host should NOT have sent a request for a repaint, since there |
| 529 // was an ACK already pending. | 535 // was an ACK already pending. |
| 530 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); | 536 EXPECT_FALSE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); |
| 531 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 537 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 532 ViewMsg_UpdateRect_ACK::ID)); | 538 ViewMsg_UpdateRect_ACK::ID)); |
| 533 } | 539 } |
| 534 | 540 |
| 535 // Tests getting the backing store with the renderer sending a repaint ack. | 541 // Tests getting the backing store with the renderer sending a repaint ack. |
| 536 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) { | 542 TEST_F(RenderWidgetHostTest, GetBackingStore_RepaintAck) { |
| 543 // First set the view size to match what the renderer is rendering. |
| 544 ViewHostMsg_UpdateRect_Params params; |
| 545 process_->InitUpdateRectParams(¶ms); |
| 546 view_->set_bounds(gfx::Rect(params.view_size)); |
| 547 |
| 537 // Doing a request request with the update message allowed should work and | 548 // Doing a request request with the update message allowed should work and |
| 538 // the repaint ack should work. | 549 // the repaint ack should work. |
| 539 process_->set_update_msg_should_reply(true); | 550 process_->set_update_msg_should_reply(true); |
| 540 process_->set_update_msg_reply_flags( | 551 process_->set_update_msg_reply_flags( |
| 541 ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK); | 552 ViewHostMsg_UpdateRect_Flags::IS_REPAINT_ACK); |
| 542 BackingStore* backing = host_->GetBackingStore(true); | 553 BackingStore* backing = host_->GetBackingStore(true); |
| 543 EXPECT_TRUE(backing); | 554 EXPECT_TRUE(backing); |
| 544 // We still should not have sent out a repaint request since the last flags | 555 // We still should not have sent out a repaint request since the last flags |
| 545 // didn't have the repaint ack set, and the pending flag will still be set. | 556 // didn't have the repaint ack set, and the pending flag will still be set. |
| 546 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); | 557 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching(ViewMsg_Repaint::ID)); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 810 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 800 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 811 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 801 SendInputEventACK(WebInputEvent::RawKeyDown, true); | 812 SendInputEventACK(WebInputEvent::RawKeyDown, true); |
| 802 | 813 |
| 803 // Wait long enough for first timeout and see if it fired. | 814 // Wait long enough for first timeout and see if it fired. |
| 804 MessageLoop::current()->PostDelayedTask( | 815 MessageLoop::current()->PostDelayedTask( |
| 805 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); | 816 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); |
| 806 MessageLoop::current()->Run(); | 817 MessageLoop::current()->Run(); |
| 807 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 818 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
| 808 } | 819 } |
| OLD | NEW |