summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host/backing_store_proxy.cc
blob: b39eebd181d38445691564f5ef5a044464db17ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/renderer_host/backing_store_proxy.h"

#include "base/gfx/rect.h"
#include "chrome/browser/gpu_process_host.h"
#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/render_widget_host.h"
#include "chrome/common/gpu_messages.h"
#include "chrome/common/render_messages.h"

BackingStoreProxy::BackingStoreProxy(RenderWidgetHost* widget,
                                     const gfx::Size& size,
                                     GpuProcessHost* process,
                                     int32 routing_id)
    : BackingStore(widget, size),
      process_(process),
      routing_id_(routing_id),
      waiting_for_paint_ack_(false) {
  process_->AddRoute(routing_id_, this);
}

BackingStoreProxy::~BackingStoreProxy() {
  process_->RemoveRoute(routing_id_);
}

void BackingStoreProxy::PaintToBackingStore(
    RenderProcessHost* process,
    TransportDIB::Id bitmap,
    const gfx::Rect& bitmap_rect,
    const std::vector<gfx::Rect>& copy_rects,
    bool* painted_synchronously) {
  DCHECK(!waiting_for_paint_ack_);

  if (process_->Send(new GpuMsg_PaintToBackingStore(
         routing_id_, ::GetProcessId(process->GetHandle()),
         bitmap, bitmap_rect, copy_rects))) {
    // Message sent successfully, so the caller can not destroy the
    // TransportDIB. OnDonePaintingToBackingStore will free it later.
    *painted_synchronously = false;
    waiting_for_paint_ack_ = true;
  } else {
    // On error, we're done with the TransportDIB and the caller can free it.
    *painted_synchronously = true;
  }
}

bool BackingStoreProxy::CopyFromBackingStore(const gfx::Rect& rect,
                                             skia::PlatformCanvas* output) {
  NOTIMPLEMENTED();
  return false;
}

void BackingStoreProxy::ScrollBackingStore(int dx, int dy,
                                           const gfx::Rect& clip_rect,
                                           const gfx::Size& view_size) {
  process_->Send(new GpuMsg_ScrollBackingStore(routing_id_, dx, dy,
                                               clip_rect, view_size));
}

void BackingStoreProxy::OnMessageReceived(const IPC::Message& msg) {
  IPC_BEGIN_MESSAGE_MAP(BackingStoreProxy, msg)
    IPC_MESSAGE_HANDLER(GpuHostMsg_PaintToBackingStore_ACK,
                        OnPaintToBackingStoreACK)
  IPC_END_MESSAGE_MAP_EX()
}

void BackingStoreProxy::OnChannelConnected(int32 peer_pid) {
}

void BackingStoreProxy::OnChannelError() {
  if (waiting_for_paint_ack_) {
    // If the GPU process dies while painting, the renderer will be waiting for
    // the paint ACK before painting any more. Since no ack is coming, we
    // manually declare that we're done with the transport DIB here so it can
    // continue.
    OnPaintToBackingStoreACK();
  }

  // FIXME(brettw) does this mean we aren't getting any more messages and we
  // should delete outselves?
}

void BackingStoreProxy::OnPaintToBackingStoreACK() {
  DCHECK(waiting_for_paint_ack_);
  render_widget_host()->DonePaintingToBackingStore();
  waiting_for_paint_ack_ = false;
}