Commit c88c9447 authored by thakis@chromium.org's avatar thakis@chromium.org

Let PaintAtAck send an int tag instead of the TransportDIB handle.

TransportDIB handles are file descriptors on mac, which are duped when sent over IPC. Hence, they change their value, and the handle that comes back over IPC is not the same that was originally sent -- so they can't be used as map keys.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/3037006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52925 0039d316-1c4b-4281-b951-d872f2087c98
parent 36df43b1
......@@ -298,12 +298,13 @@ void RenderWidgetHost::SetIsLoading(bool is_loading) {
}
void RenderWidgetHost::PaintAtSize(TransportDIB::Handle dib_handle,
int tag,
const gfx::Size& page_size,
const gfx::Size& desired_size) {
// Ask the renderer to create a bitmap regardless of whether it's
// hidden, being resized, redrawn, etc. It resizes the web widget
// to the page_size and then scales it to the desired_size.
Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle,
Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle, tag,
page_size, desired_size));
}
......@@ -707,10 +708,9 @@ void RenderWidgetHost::OnMsgRequestMove(const gfx::Rect& pos) {
}
}
void RenderWidgetHost::OnMsgPaintAtSizeAck(
const TransportDIB::Handle& dib_handle, const gfx::Size& size) {
void RenderWidgetHost::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) {
if (painting_observer_) {
painting_observer_->WidgetDidReceivePaintAtSizeAck(this, dib_handle, size);
painting_observer_->WidgetDidReceivePaintAtSizeAck(this, tag, size);
}
}
......
......@@ -222,6 +222,7 @@ class RenderWidgetHost : public IPC::Channel::Listener,
// logic that is normally invoked, and doesn't put the results into
// the backing store.
void PaintAtSize(TransportDIB::Handle dib_handle,
int tag,
const gfx::Size& page_size,
const gfx::Size& desired_size);
......@@ -473,8 +474,7 @@ class RenderWidgetHost : public IPC::Channel::Listener,
void OnMsgRenderViewGone();
void OnMsgClose();
void OnMsgRequestMove(const gfx::Rect& pos);
void OnMsgPaintAtSizeAck(const TransportDIB::Handle& dib_handle,
const gfx::Size& size);
void OnMsgPaintAtSizeAck(int tag, const gfx::Size& size);
void OnMsgUpdateRect(const ViewHostMsg_UpdateRect_Params& params);
void OnMsgCreateVideo(const gfx::Size& size);
void OnMsgUpdateVideo(TransportDIB::Id bitmap, const gfx::Rect& bitmap_rect);
......
......@@ -31,7 +31,7 @@ class RenderWidgetHostPaintingObserver {
// received.
virtual void WidgetDidReceivePaintAtSizeAck(
RenderWidgetHost* widget,
const TransportDIB::Handle& dib_handle,
int tag,
const gfx::Size& size) = 0;
};
......
......@@ -204,20 +204,20 @@ class MockPaintingObserver : public RenderWidgetHostPaintingObserver {
BackingStore* backing_store) {}
void WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {}
void WidgetDidReceivePaintAtSizeAck(RenderWidgetHost* host,
const TransportDIB::Handle& dib_handle,
int tag,
const gfx::Size& size) {
host_ = reinterpret_cast<MockRenderWidgetHost*>(host);
dib_handle_ = dib_handle;
tag_ = tag;
size_ = size;
}
MockRenderWidgetHost* host() const { return host_; }
TransportDIB::Handle dib_handle() const { return dib_handle_; }
int tag() const { return tag_; }
gfx::Size size() const { return size_; }
private:
MockRenderWidgetHost* host_;
TransportDIB::Handle dib_handle_;
int tag_;
gfx::Size size_;
};
......@@ -536,19 +536,18 @@ TEST_F(RenderWidgetHostTest, HiddenPaint) {
}
TEST_F(RenderWidgetHostTest, PaintAtSize) {
host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), gfx::Size(40, 60),
gfx::Size(20, 30));
const int kPaintAtSizeTag = 42;
host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), kPaintAtSizeTag,
gfx::Size(40, 60), gfx::Size(20, 30));
EXPECT_TRUE(
process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID));
MockPaintingObserver observer;
host_->set_painting_observer(&observer);
// Need to generate a fake handle value on all platforms.
TransportDIB::Handle handle = TransportDIB::GetFakeHandleForTest();
host_->OnMsgPaintAtSizeAck(handle, gfx::Size(20, 30));
EXPECT_TRUE(host_ == observer.host());
EXPECT_TRUE(handle == observer.dib_handle());
host_->OnMsgPaintAtSizeAck(kPaintAtSizeTag, gfx::Size(20, 30));
EXPECT_EQ(host_.get(), observer.host());
EXPECT_EQ(kPaintAtSizeTag, observer.tag());
EXPECT_EQ(20, observer.size().width());
EXPECT_EQ(30, observer.size().height());
host_->set_painting_observer(NULL);
......
......@@ -191,14 +191,15 @@ void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer,
// We are going to render the thumbnail asynchronously now, so keep
// this callback for later lookup when the rendering is done.
static int sequence_num = 0;
sequence_num++;
TransportDIB* thumbnail_dib = TransportDIB::Create(
desired_size.width() * desired_size.height() * 4, sequence_num++);
desired_size.width() * desired_size.height() * 4, sequence_num);
linked_ptr<AsyncRequestInfo> request_info(new AsyncRequestInfo);
request_info->callback.reset(callback);
request_info->thumbnail_dib.reset(thumbnail_dib);
request_info->renderer = renderer;
ThumbnailCallbackMap::value_type new_value(thumbnail_dib->handle(),
request_info);
ThumbnailCallbackMap::value_type new_value(sequence_num, request_info);
std::pair<ThumbnailCallbackMap::iterator, bool> result =
callback_map_.insert(new_value);
if (!result.second) {
......@@ -206,7 +207,8 @@ void ThumbnailGenerator::AskForSnapshot(RenderWidgetHost* renderer,
return;
}
renderer->PaintAtSize(thumbnail_dib->handle(), page_size, desired_size);
renderer->PaintAtSize(
thumbnail_dib->handle(), sequence_num, page_size, desired_size);
}
SkBitmap ThumbnailGenerator::GetThumbnailForRenderer(
......@@ -290,10 +292,10 @@ void ThumbnailGenerator::WidgetDidUpdateBackingStore(RenderWidgetHost* widget) {
void ThumbnailGenerator::WidgetDidReceivePaintAtSizeAck(
RenderWidgetHost* widget,
const TransportDIB::Handle& dib_handle,
int sequence_num,
const gfx::Size& size) {
// Lookup the callback, run it, and erase it.
ThumbnailCallbackMap::iterator item = callback_map_.find(dib_handle);
ThumbnailCallbackMap::iterator item = callback_map_.find(sequence_num);
if (item != callback_map_.end()) {
TransportDIB* dib = item->second->thumbnail_dib.get();
DCHECK(dib);
......
......@@ -80,7 +80,7 @@ class ThumbnailGenerator : public RenderWidgetHostPaintingObserver,
virtual void WidgetDidReceivePaintAtSizeAck(
RenderWidgetHost* widget,
const TransportDIB::Handle& dib_handle,
int tag,
const gfx::Size& size);
// NotificationObserver interface.
......@@ -118,9 +118,9 @@ class ThumbnailGenerator : public RenderWidgetHostPaintingObserver,
// See the setter above.
bool no_timeout_;
// Map of callback objects by TransportDIB::Handle.
// Map of callback objects by sequence number.
struct AsyncRequestInfo;
typedef std::map<TransportDIB::Handle,
typedef std::map<int,
linked_ptr<AsyncRequestInfo> > ThumbnailCallbackMap;
ThumbnailCallbackMap callback_map_;
......
......@@ -153,8 +153,11 @@ IPC_BEGIN_MESSAGES(View)
// it. In response to this message, the host generates a
// ViewHostMsg_PaintAtSize_ACK message. Note that the DIB *must* be
// the right size to receive an RGBA image at the |desired_size|.
IPC_MESSAGE_ROUTED3(ViewMsg_PaintAtSize,
// |tag| is sent along with ViewHostMsg_PaintAtSize_ACK unmodified to
// identify the PaintAtSize message the ACK belongs to.
IPC_MESSAGE_ROUTED4(ViewMsg_PaintAtSize,
TransportDIB::Handle /* dib_handle */,
int /* tag */,
gfx::Size /* page_size */,
gfx::Size /* desired_size */)
......@@ -1123,9 +1126,10 @@ IPC_BEGIN_MESSAGES(ViewHost)
show the POST interstitial */ )
// Tells the render view that a ViewHostMsg_PaintAtSize message was
// processed, and the DIB is ready for use.
// processed, and the DIB is ready for use. |tag| has the same value that
// the tag sent along with ViewMsg_PaintAtSize.
IPC_MESSAGE_ROUTED2(ViewHostMsg_PaintAtSize_ACK,
TransportDIB::Handle /* dib_handle */,
int /* tag */,
gfx::Size /* size */)
// Sent to update part of the view. In response to this message, the host
......
......@@ -742,6 +742,7 @@ void RenderWidget::OnImeConfirmComposition() {
// This message causes the renderer to render an image of the
// desired_size, regardless of whether the tab is hidden or not.
void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
int tag,
const gfx::Size& page_size,
const gfx::Size& desired_size) {
if (!webwidget_ || dib_handle == TransportDIB::DefaultHandleValue())
......@@ -750,9 +751,7 @@ void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
if (page_size.IsEmpty() || desired_size.IsEmpty()) {
// If one of these is empty, then we just return the dib we were
// given, to avoid leaking it.
Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_,
dib_handle,
desired_size));
Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, desired_size));
return;
}
......@@ -807,7 +806,7 @@ void RenderWidget::OnMsgPaintAtSize(const TransportDIB::Handle& dib_handle,
// Return the widget to its previous size.
webwidget_->resize(old_size);
Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, dib_handle, bounds.size()));
Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
}
void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
......
......@@ -166,6 +166,7 @@ class RenderWidget : public IPC::Channel::Listener,
int selection_end);
void OnImeConfirmComposition();
void OnMsgPaintAtSize(const TransportDIB::Handle& dib_id,
int tag,
const gfx::Size& page_size,
const gfx::Size& desired_size);
void OnMsgRepaint(const gfx::Size& size_to_paint);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment