OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/renderer_host/backing_store_proxy.h" | |
6 | |
7 #include "build/build_config.h" | |
8 #include "chrome/browser/gpu_process_host_ui_shim.h" | |
9 #include "chrome/browser/renderer_host/render_process_host.h" | |
10 #include "chrome/browser/renderer_host/render_widget_host.h" | |
11 #include "chrome/common/gpu_messages.h" | |
12 #include "chrome/common/render_messages.h" | |
13 #include "gfx/rect.h" | |
14 | |
15 #if defined(OS_WIN) | |
16 #include <windows.h> | |
17 #endif | |
18 | |
19 BackingStoreProxy::BackingStoreProxy(RenderWidgetHost* widget, | |
20 const gfx::Size& size, | |
21 GpuProcessHostUIShim* process_shim, | |
22 int32 routing_id) | |
23 : BackingStore(widget, size), | |
24 process_shim_(process_shim), | |
25 routing_id_(routing_id), | |
26 waiting_for_paint_ack_(false) { | |
27 process_shim_->AddRoute(routing_id_, this); | |
28 } | |
29 | |
30 BackingStoreProxy::~BackingStoreProxy() { | |
31 process_shim_->RemoveRoute(routing_id_); | |
32 } | |
33 | |
34 void BackingStoreProxy::PaintToBackingStore( | |
35 RenderProcessHost* process, | |
36 TransportDIB::Id bitmap, | |
37 const gfx::Rect& bitmap_rect, | |
38 const std::vector<gfx::Rect>& copy_rects, | |
39 bool* painted_synchronously) { | |
40 DCHECK(!waiting_for_paint_ack_); | |
41 | |
42 base::ProcessId process_id; | |
43 #if defined(OS_WIN) | |
44 process_id = ::GetProcessId(process->GetHandle()); | |
45 #elif defined(OS_POSIX) | |
46 process_id = process->GetHandle(); | |
47 #endif | |
48 | |
49 if (process_shim_->Send(new GpuMsg_PaintToBackingStore( | |
50 routing_id_, process_id, bitmap, bitmap_rect, copy_rects))) { | |
51 // Message sent successfully, so the caller can not destroy the | |
52 // TransportDIB. OnDonePaintingToBackingStore will free it later. | |
53 *painted_synchronously = false; | |
54 waiting_for_paint_ack_ = true; | |
55 } else { | |
56 // On error, we're done with the TransportDIB and the caller can free it. | |
57 *painted_synchronously = true; | |
58 } | |
59 } | |
60 | |
61 bool BackingStoreProxy::CopyFromBackingStore(const gfx::Rect& rect, | |
62 skia::PlatformCanvas* output) { | |
63 NOTIMPLEMENTED(); | |
64 return false; | |
65 } | |
66 | |
67 void BackingStoreProxy::ScrollBackingStore(int dx, int dy, | |
68 const gfx::Rect& clip_rect, | |
69 const gfx::Size& view_size) { | |
70 process_shim_->Send(new GpuMsg_ScrollBackingStore(routing_id_, dx, dy, | |
71 clip_rect, view_size)); | |
72 } | |
73 | |
74 void BackingStoreProxy::OnMessageReceived(const IPC::Message& msg) { | |
75 IPC_BEGIN_MESSAGE_MAP(BackingStoreProxy, msg) | |
76 IPC_MESSAGE_HANDLER(GpuHostMsg_PaintToBackingStore_ACK, | |
77 OnPaintToBackingStoreACK) | |
78 IPC_END_MESSAGE_MAP_EX() | |
79 } | |
80 | |
81 void BackingStoreProxy::OnChannelConnected(int32 peer_pid) { | |
82 } | |
83 | |
84 void BackingStoreProxy::OnChannelError() { | |
85 if (waiting_for_paint_ack_) { | |
86 // If the GPU process dies while painting, the renderer will be waiting for | |
87 // the paint ACK before painting any more. Since no ack is coming, we | |
88 // manually declare that we're done with the transport DIB here so it can | |
89 // continue. | |
90 OnPaintToBackingStoreACK(); | |
91 } | |
92 | |
93 // TODO(brettw): does this mean we aren't getting any more messages and we | |
94 // should delete outselves? | |
95 } | |
96 | |
97 void BackingStoreProxy::OnPaintToBackingStoreACK() { | |
98 DCHECK(waiting_for_paint_ack_); | |
99 render_widget_host()->DonePaintingToBackingStore(); | |
100 waiting_for_paint_ack_ = false; | |
101 } | |
OLD | NEW |