Commit 5501d5df authored by lazyboy@chromium.org's avatar lazyboy@chromium.org

Remove SW rendering path code from BrowserPlugin.

BUG=364560
Test=This changes the internals of rendering <webview> in chrome-apps. No noticeable changes should be observed.

Review URL: https://codereview.chromium.org/251593004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266797 0039d316-1c4b-4281-b951-d872f2087c98
parent 3a98b39b
......@@ -25,7 +25,6 @@
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/content_constants_internal.h"
#include "content/common/drag_messages.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
#include "content/port/browser/render_view_host_delegate_view.h"
......@@ -33,9 +32,7 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/resource_request_details.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_view.h"
......@@ -47,7 +44,6 @@
#include "net/url_request/url_request.h"
#include "third_party/WebKit/public/platform/WebCursorInfo.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/surface/transport_dib.h"
#include "webkit/common/resource_type.h"
#if defined(OS_MACOSX)
......@@ -198,9 +194,6 @@ BrowserPluginGuest::BrowserPluginGuest(
: WebContentsObserver(web_contents),
embedder_web_contents_(NULL),
instance_id_(instance_id),
damage_buffer_sequence_id_(0),
damage_buffer_size_(0),
damage_buffer_scale_factor_(1.0f),
guest_device_scale_factor_(1.0f),
guest_hang_timeout_(
base::TimeDelta::FromMilliseconds(kHungRendererDelayMs)),
......@@ -401,7 +394,6 @@ bool BrowserPluginGuest::OnMessageReceivedFromEmbedder(
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetVisibility, OnSetVisibility)
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UnlockMouse_ACK, OnUnlockMouseAck)
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateGeometry, OnUpdateGeometry)
IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
......@@ -776,41 +768,6 @@ WebContentsImpl* BrowserPluginGuest::GetWebContents() {
return static_cast<WebContentsImpl*>(web_contents());
}
base::SharedMemory* BrowserPluginGuest::GetDamageBufferFromEmbedder(
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
if (!attached()) {
LOG(WARNING) << "Attempting to map a damage buffer prior to attachment.";
return NULL;
}
#if defined(OS_WIN)
base::ProcessHandle handle =
embedder_web_contents_->GetRenderProcessHost()->GetHandle();
scoped_ptr<base::SharedMemory> shared_buf(
new base::SharedMemory(params.damage_buffer_handle, false, handle));
#elif defined(OS_POSIX)
scoped_ptr<base::SharedMemory> shared_buf(
new base::SharedMemory(params.damage_buffer_handle, false));
#endif
if (!shared_buf->Map(params.damage_buffer_size)) {
LOG(WARNING) << "Unable to map the embedder's damage buffer.";
return NULL;
}
return shared_buf.release();
}
void BrowserPluginGuest::SetDamageBuffer(
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
damage_buffer_.reset(GetDamageBufferFromEmbedder(params));
// Sanity check: Verify that we've correctly shared the damage buffer memory
// between the embedder and browser processes.
DCHECK(!damage_buffer_ ||
*static_cast<unsigned int*>(damage_buffer_->memory()) == 0xdeadbeef);
damage_buffer_sequence_id_ = params.damage_buffer_sequence_id;
damage_buffer_size_ = params.damage_buffer_size;
damage_view_size_ = params.view_rect.size();
damage_buffer_scale_factor_ = params.scale_factor;
}
gfx::Point BrowserPluginGuest::GetScreenCoordinates(
const gfx::Point& relative_position) const {
gfx::Point screen_pos(relative_position);
......@@ -941,7 +898,7 @@ void BrowserPluginGuest::RenderViewReady() {
if (auto_size_enabled_)
rvh->EnableAutoResize(min_auto_size_, max_auto_size_);
else
rvh->DisableAutoResize(damage_view_size_);
rvh->DisableAutoResize(full_size_);
Send(new ViewMsg_SetName(routing_id(), name_));
OnSetContentsOpaque(instance_id_, guest_opaque_);
......@@ -997,7 +954,6 @@ bool BrowserPluginGuest::ShouldForwardToBrowserPluginGuest(
case BrowserPluginHostMsg_SetVisibility::ID:
case BrowserPluginHostMsg_UnlockMouse_ACK::ID:
case BrowserPluginHostMsg_UpdateGeometry::ID:
case BrowserPluginHostMsg_UpdateRect_ACK::ID:
return true;
default:
return false;
......@@ -1320,10 +1276,8 @@ void BrowserPluginGuest::OnResizeGuest(
delegate_->SizeChanged(last_seen_view_size_, params.view_rect.size());
last_seen_auto_size_enabled_ = false;
}
// Invalid damage buffer means we are in HW compositing mode,
// so just resize the WebContents and repaint if needed.
if (base::SharedMemory::IsHandleValid(params.damage_buffer_handle))
SetDamageBuffer(params);
// Just resize the WebContents and repaint if needed.
full_size_ = params.view_rect.size();
if (!params.view_rect.size().IsEmpty())
GetWebContents()->GetView()->SizeContents(params.view_rect.size());
if (params.repaint)
......@@ -1370,10 +1324,9 @@ void BrowserPluginGuest::OnSetSize(
GetWebContents()->GetRenderViewHost()->EnableAutoResize(
min_auto_size_, max_auto_size_);
// TODO(fsamuel): If we're changing autosize parameters, then we force
// the guest to completely repaint itself, because BrowserPlugin has
// allocated a new damage buffer and expects a full frame of pixels.
// Ideally, we shouldn't need to do this because we shouldn't need to
// allocate a new damage buffer unless |max_auto_size_| has changed.
// the guest to completely repaint itself.
// Ideally, we shouldn't need to do this unless |max_auto_size_| has
// changed.
// However, even in that case, layout may not change and so we may
// not get a full frame worth of pixels.
Send(new ViewMsg_Repaint(routing_id(), max_auto_size_));
......@@ -1425,13 +1378,6 @@ void BrowserPluginGuest::OnUnlockMouseAck(int instance_id) {
mouse_locked_ = false;
}
void BrowserPluginGuest::OnUpdateRectACK(
int instance_id,
const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params) {
OnSetSize(instance_id_, auto_size_params, resize_guest_params);
}
void BrowserPluginGuest::OnCopyFromCompositingSurfaceAck(
int instance_id,
int request_id,
......@@ -1530,7 +1476,6 @@ void BrowserPluginGuest::OnUpdateRect(
relay_params.scale_factor = params.scale_factor;
relay_params.is_resize_ack = ViewHostMsg_UpdateRect_Flags::is_resize_ack(
params.flags);
relay_params.needs_ack = false;
bool size_changed = last_seen_view_size_ != params.view_size;
gfx::Size old_size = last_seen_view_size_;
......@@ -1542,7 +1487,6 @@ void BrowserPluginGuest::OnUpdateRect(
}
last_seen_auto_size_enabled_ = auto_size_enabled_;
relay_params.damage_buffer_sequence_id = 0;
SendMessageToEmbedder(
new BrowserPluginMsg_UpdateRect(instance_id(), relay_params));
}
......
......@@ -22,8 +22,6 @@
#include <queue>
#include "base/compiler_specific.h"
#include "base/id_map.h"
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "content/common/edit_command.h"
......@@ -44,19 +42,13 @@
struct BrowserPluginHostMsg_AutoSize_Params;
struct BrowserPluginHostMsg_Attach_Params;
struct BrowserPluginHostMsg_ResizeGuest_Params;
struct FrameHostMsg_BuffersSwappedACK_Params;
struct FrameHostMsg_CompositorFrameSwappedACK_Params;
struct FrameHostMsg_ReclaimCompositorResources_Params;
struct ViewHostMsg_CreateWindow_Params;
#if defined(OS_MACOSX)
struct ViewHostMsg_ShowPopup_Params;
#endif
struct ViewHostMsg_UpdateRect_Params;
namespace cc {
class CompositorFrameAck;
}
namespace blink {
class WebInputEvent;
}
......@@ -65,16 +57,9 @@ namespace gfx {
class Range;
}
namespace gpu {
struct Mailbox;
}
namespace content {
class BrowserPluginHostFactory;
class BrowserPluginEmbedder;
class BrowserPluginGuestManager;
class RenderProcessHost;
class RenderWidgetHostView;
class SiteInstance;
class WebCursor;
......@@ -149,7 +134,6 @@ class CONTENT_EXPORT BrowserPluginGuest
bool focused() const { return focused_; }
bool visible() const { return guest_visible_; }
void clear_damage_buffer() { damage_buffer_.reset(); }
bool is_in_destruction() { return is_in_destruction_; }
BrowserPluginGuest* opener() const { return opener_.get(); }
......@@ -238,10 +222,6 @@ class CONTENT_EXPORT BrowserPluginGuest
// Exposes the protected web_contents() from WebContentsObserver.
WebContentsImpl* GetWebContents();
// Overridden in tests.
virtual void SetDamageBuffer(
const BrowserPluginHostMsg_ResizeGuest_Params& params);
gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const;
// Helper to send messages to embedder. This methods fills the message with
......@@ -339,15 +319,6 @@ class CONTENT_EXPORT BrowserPluginGuest
// BrowserPluginGuest.
BrowserPluginGuest* CreateNewGuestWindow(const OpenURLParams& params);
base::SharedMemory* damage_buffer() const { return damage_buffer_.get(); }
const gfx::Size& damage_view_size() const { return damage_view_size_; }
float damage_buffer_scale_factor() const {
return damage_buffer_scale_factor_;
}
// Returns the damage buffer corresponding to the handle in resize |params|.
base::SharedMemory* GetDamageBufferFromEmbedder(
const BrowserPluginHostMsg_ResizeGuest_Params& params);
bool InAutoSizeBounds(const gfx::Size& size) const;
void RequestNewWindowPermission(WindowOpenDisposition disposition,
......@@ -382,7 +353,7 @@ class CONTENT_EXPORT BrowserPluginGuest
int instance_id,
const FrameHostMsg_ReclaimCompositorResources_Params& params);
// Overriden in tests.
// Overridden in tests.
virtual void OnHandleInputEvent(int instance_id,
const gfx::Rect& guest_window_rect,
const blink::WebInputEvent* event);
......@@ -392,11 +363,11 @@ class CONTENT_EXPORT BrowserPluginGuest
void OnLockMouseAck(int instance_id, bool succeeded);
void OnNavigateGuest(int instance_id, const std::string& src);
void OnPluginDestroyed(int instance_id);
// Grab the new damage buffer from the embedder, and resize the guest's
// web contents.
void OnResizeGuest(int instance_id,
const BrowserPluginHostMsg_ResizeGuest_Params& params);
// Overriden in tests.
// Resizes the guest's web contents.
// Overridden in tests.
virtual void OnResizeGuest(
int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params);
// Overridden in tests.
virtual void OnSetFocus(int instance_id, bool focused);
// Sets the name of the guest so that other guests in the same partition can
// access it.
......@@ -429,10 +400,6 @@ class CONTENT_EXPORT BrowserPluginGuest
void OnUnlockMouse();
void OnUnlockMouseAck(int instance_id);
void OnUpdateGeometry(int instance_id, const gfx::Rect& view_rect);
void OnUpdateRectACK(
int instance_id,
const BrowserPluginHostMsg_AutoSize_Params& auto_size_params,
const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params);
void OnTextInputTypeChanged(ui::TextInputType type,
ui::TextInputMode input_mode,
......@@ -470,7 +437,7 @@ class CONTENT_EXPORT BrowserPluginGuest
void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params);
#endif
void OnShowWidget(int route_id, const gfx::Rect& initial_pos);
// Overriden in tests.
// Overridden in tests.
virtual void OnTakeFocus(bool reverse);
void OnUpdateFrameName(int frame_id,
bool is_top_level,
......@@ -496,12 +463,6 @@ class CONTENT_EXPORT BrowserPluginGuest
// An identifier that uniquely identifies a browser plugin guest within an
// embedder.
int instance_id_;
scoped_ptr<base::SharedMemory> damage_buffer_;
// An identifier that uniquely identifies a damage buffer.
uint32 damage_buffer_sequence_id_;
size_t damage_buffer_size_;
gfx::Size damage_view_size_;
float damage_buffer_scale_factor_;
float guest_device_scale_factor_;
gfx::Rect guest_window_rect_;
gfx::Rect guest_screen_rect_;
......@@ -516,6 +477,7 @@ class CONTENT_EXPORT BrowserPluginGuest
bool auto_size_enabled_;
gfx::Size max_auto_size_;
gfx::Size min_auto_size_;
gfx::Size full_size_;
// Each copy-request is identified by a unique number. The unique number is
// used to keep track of the right callback.
......
......@@ -359,12 +359,7 @@ IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateAfterResize) {
StartBrowserPluginTest(kEmbedderURL, kHTMLForGuest, true, embedder_code);
// Wait for the guest to be resized to 100x200.
test_guest()->WaitForViewSize(nxt_size);
// TODO(lazyboy): Instead do the following once it's not flaky.
// Wait for the guest to receive a damage buffer of size 100x200.
// This means the guest will be painted properly at that size.
// test_guest()->WaitForDamageBufferWithSize(nxt_size);
test_guest()->WaitForResizeGuest(nxt_size);
}
IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, AdvanceFocus) {
......
......@@ -18,18 +18,14 @@ TestBrowserPluginGuest::TestBrowserPluginGuest(
WebContentsImpl* web_contents)
: BrowserPluginGuest(instance_id, false, web_contents, NULL),
update_rect_count_(0),
damage_buffer_call_count_(0),
exit_observed_(false),
focus_observed_(false),
blur_observed_(false),
advance_focus_observed_(false),
was_hidden_observed_(false),
set_damage_buffer_observed_(false),
input_observed_(false),
load_stop_observed_(false),
ime_cancel_observed_(false),
waiting_for_damage_buffer_with_size_(false),
last_damage_buffer_size_(gfx::Size()) {
ime_cancel_observed_(false) {
}
TestBrowserPluginGuest::~TestBrowserPluginGuest() {
......@@ -69,17 +65,6 @@ void TestBrowserPluginGuest::ResetUpdateRectCount() {
update_rect_count_ = 0;
}
void TestBrowserPluginGuest::WaitForDamageBufferWithSize(
const gfx::Size& size) {
if (damage_buffer_call_count_ > 0 && last_damage_buffer_size_ == size)
return;
expected_damage_buffer_size_ = size;
waiting_for_damage_buffer_with_size_ = true;
damage_buffer_message_loop_runner_ = new MessageLoopRunner();
damage_buffer_message_loop_runner_->Run();
}
void TestBrowserPluginGuest::RenderProcessGone(base::TerminationStatus status) {
exit_observed_ = true;
if (status != base::TERMINATION_STATUS_NORMAL_TERMINATION &&
......@@ -193,6 +178,18 @@ void TestBrowserPluginGuest::WaitForImeCancel() {
ime_cancel_observed_ = false;
}
void TestBrowserPluginGuest::WaitForResizeGuest(const gfx::Size& view_size) {
if (last_size_observed_in_resize_ == view_size) {
last_size_observed_in_resize_ = gfx::Size();
return;
}
expected_view_size_in_resize_ = view_size;
resize_guest_message_loop_runner_ = new MessageLoopRunner();
resize_guest_message_loop_runner_->Run();
last_size_observed_in_resize_ = gfx::Size();
}
void TestBrowserPluginGuest::OnSetFocus(int instance_id, bool focused) {
if (focused) {
focus_observed_ = true;
......@@ -213,21 +210,6 @@ void TestBrowserPluginGuest::OnTakeFocus(bool reverse) {
BrowserPluginGuest::OnTakeFocus(reverse);
}
void TestBrowserPluginGuest::SetDamageBuffer(
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
++damage_buffer_call_count_;
last_damage_buffer_size_ = params.view_rect.size();
if (waiting_for_damage_buffer_with_size_ &&
expected_damage_buffer_size_ == params.view_rect.size() &&
damage_buffer_message_loop_runner_) {
damage_buffer_message_loop_runner_->Quit();
waiting_for_damage_buffer_with_size_ = false;
}
BrowserPluginGuest::SetDamageBuffer(params);
}
void TestBrowserPluginGuest::DidStopLoading(
RenderViewHost* render_view_host) {
BrowserPluginGuest::DidStopLoading(render_view_host);
......@@ -245,6 +227,18 @@ void TestBrowserPluginGuest::OnImeCancelComposition() {
BrowserPluginGuest::OnImeCancelComposition();
}
void TestBrowserPluginGuest::OnResizeGuest(
int instance_id,
const BrowserPluginHostMsg_ResizeGuest_Params& params) {
last_size_observed_in_resize_ = params.view_rect.size();
if (last_size_observed_in_resize_ == expected_view_size_in_resize_ &&
resize_guest_message_loop_runner_) {
resize_guest_message_loop_runner_->Quit();
}
BrowserPluginGuest::OnResizeGuest(instance_id, params);
}
void TestBrowserPluginGuest::WasHidden() {
was_hidden_observed_ = true;
if (was_hidden_message_loop_runner_)
......
......@@ -34,10 +34,11 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
const blink::WebInputEvent* event) OVERRIDE;
virtual void OnSetFocus(int instance_id, bool focused) OVERRIDE;
virtual void OnTakeFocus(bool reverse) OVERRIDE;
virtual void SetDamageBuffer(
const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
virtual void OnImeCancelComposition() OVERRIDE;
virtual void OnResizeGuest(
int instance_id,
const BrowserPluginHostMsg_ResizeGuest_Params& params) OVERRIDE;
// Overridden from WebContentsObserver.
virtual void WasHidden() OVERRIDE;
......@@ -47,8 +48,6 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
// ready/rendered.
void WaitForUpdateRectMsg();
void ResetUpdateRectCount();
// Waits until a guest receives a damage buffer of the specified |size|.
void WaitForDamageBufferWithSize(const gfx::Size& size);
// Waits for focus to reach this guest.
void WaitForFocus();
// Waits for blur to reach this guest.
......@@ -67,6 +66,8 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
void WaitForViewSize(const gfx::Size& view_size);
// Waits until IME cancellation is observed.
void WaitForImeCancel();
// Waits until we have seen a resize guest of size |view_size|.
void WaitForResizeGuest(const gfx::Size& view_size);
void set_guest_hang_timeout(const base::TimeDelta& timeout) {
guest_hang_timeout_ = timeout;
......@@ -81,23 +82,18 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
virtual void SendMessageToEmbedder(IPC::Message* msg) OVERRIDE;
int update_rect_count_;
int damage_buffer_call_count_;
bool exit_observed_;
bool focus_observed_;
bool blur_observed_;
bool advance_focus_observed_;
bool was_hidden_observed_;
bool set_damage_buffer_observed_;
bool input_observed_;
bool load_stop_observed_;
bool ime_cancel_observed_;
gfx::Size last_view_size_observed_;
gfx::Size expected_auto_view_size_;
// For WaitForDamageBufferWithSize().
bool waiting_for_damage_buffer_with_size_;
gfx::Size expected_damage_buffer_size_;
gfx::Size last_damage_buffer_size_;
gfx::Size last_size_observed_in_resize_;
gfx::Size expected_view_size_in_resize_;
scoped_refptr<MessageLoopRunner> send_message_loop_runner_;
scoped_refptr<MessageLoopRunner> crash_message_loop_runner_;
......@@ -105,11 +101,11 @@ class TestBrowserPluginGuest : public BrowserPluginGuest {
scoped_refptr<MessageLoopRunner> blur_message_loop_runner_;
scoped_refptr<MessageLoopRunner> advance_focus_message_loop_runner_;
scoped_refptr<MessageLoopRunner> was_hidden_message_loop_runner_;
scoped_refptr<MessageLoopRunner> damage_buffer_message_loop_runner_;
scoped_refptr<MessageLoopRunner> input_message_loop_runner_;
scoped_refptr<MessageLoopRunner> load_stop_message_loop_runner_;
scoped_refptr<MessageLoopRunner> auto_view_size_message_loop_runner_;
scoped_refptr<MessageLoopRunner> ime_cancel_message_loop_runner_;
scoped_refptr<MessageLoopRunner> resize_guest_message_loop_runner_;
DISALLOW_COPY_AND_ASSIGN(TestBrowserPluginGuest);
};
......
......@@ -167,9 +167,6 @@ void RenderWidgetHostViewGuest::AcceleratedSurfaceBuffersSwapped(
if (!guest_)
return;
// If accelerated surface buffers are getting swapped then we're not using
// the software path.
guest_->clear_damage_buffer();
FrameMsg_BuffersSwapped_Params guest_params;
guest_params.size = params.size;
guest_params.mailbox = params.mailbox;
......@@ -192,8 +189,6 @@ void RenderWidgetHostViewGuest::OnSwapCompositorFrame(
if (!guest_)
return;
guest_->clear_damage_buffer();
if (!guest_->attached()) {
// If the guest doesn't have an embedder then there's nothing to give the
// the frame to.
......
......@@ -7,11 +7,8 @@
#include <string>
#include "base/basictypes.h"
#include "base/memory/shared_memory.h"
#include "base/process/process.h"
#include "base/values.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/compositor_frame_ack.h"
#include "content/common/content_export.h"
#include "content/common/content_param_traits.h"
#include "content/common/cursors/webcursor.h"
......@@ -49,13 +46,6 @@ IPC_STRUCT_END()
IPC_STRUCT_BEGIN(BrowserPluginHostMsg_ResizeGuest_Params)
// Indicates whether the parameters have been populated or not.
IPC_STRUCT_MEMBER(bool, size_changed)
// The sequence number used to uniquely identify the damage buffer for the
// current container size.
IPC_STRUCT_MEMBER(uint32, damage_buffer_sequence_id)
// The handle to use to map the damage buffer in the browser process.
IPC_STRUCT_MEMBER(base::SharedMemoryHandle, damage_buffer_handle)
// The size of the damage buffer.
IPC_STRUCT_MEMBER(size_t, damage_buffer_size)
// The new rect of the guest view area.
IPC_STRUCT_MEMBER(gfx::Rect, view_rect)
// Indicates the scale factor of the embedder WebView.
......@@ -87,27 +77,6 @@ IPC_STRUCT_BEGIN(BrowserPluginMsg_Attach_ACK_Params)
IPC_STRUCT_END()
IPC_STRUCT_BEGIN(BrowserPluginMsg_UpdateRect_Params)
// The sequence number of the damage buffer used by the browser process.
IPC_STRUCT_MEMBER(uint32, damage_buffer_sequence_id)
// The position and size of the bitmap.
IPC_STRUCT_MEMBER(gfx::Rect, bitmap_rect)
// The scroll delta. Only one of the delta components can be non-zero, and if
// they are both zero, then it means there is no scrolling and the scroll_rect
// is ignored.
IPC_STRUCT_MEMBER(gfx::Vector2d, scroll_delta)
// The rectangular region to scroll.
IPC_STRUCT_MEMBER(gfx::Rect, scroll_rect)
// The scroll offset of the render view.
IPC_STRUCT_MEMBER(gfx::Point, scroll_offset)
// The regions of the bitmap (in view coords) that contain updated pixels.
// In the case of scrolling, this includes the scroll damage rect.
IPC_STRUCT_MEMBER(std::vector<gfx::Rect>, copy_rects)
// The size of the RenderView when this message was generated. This is
// included so the host knows how large the view is from the perspective of
// the renderer process. This is necessary in case a resize operation is in
......@@ -121,10 +90,6 @@ IPC_STRUCT_BEGIN(BrowserPluginMsg_UpdateRect_Params)
// Is this UpdateRect an ACK to a resize request?
IPC_STRUCT_MEMBER(bool, is_resize_ack)
// Used in HW accelerated case to switch between sending an UpdateRect_ACK
// with the new size or just resizing.
IPC_STRUCT_MEMBER(bool, needs_ack)
IPC_STRUCT_END()
// Browser plugin messages
......@@ -202,15 +167,6 @@ IPC_MESSAGE_ROUTED3(BrowserPluginHostMsg_HandleInputEvent,
gfx::Rect /* guest_window_rect */,
IPC::WebInputEventPointer /* event */)
// An ACK to the guest process letting it know that the embedder has handled
// the previous frame and is ready for the next frame. If the guest sent the
// embedder a bitmap that does not match the size of the BrowserPlugin's
// container, the BrowserPlugin requests a new size as well.
IPC_MESSAGE_ROUTED3(BrowserPluginHostMsg_UpdateRect_ACK,
int /* instance_id */,
BrowserPluginHostMsg_AutoSize_Params /* auto_size_params */,
BrowserPluginHostMsg_ResizeGuest_Params /* resize_guest_params */)
// A BrowserPlugin sends this to BrowserPluginEmbedder (browser process) when it
// wants to navigate to a given src URL. If a guest WebContents already exists,
// it will navigate that WebContents. If not, it will create the WebContents,
......
......@@ -93,8 +93,6 @@
'renderer/android/synchronous_compositor_factory.h',
'renderer/browser_plugin/browser_plugin.cc',
'renderer/browser_plugin/browser_plugin.h',
'renderer/browser_plugin/browser_plugin_backing_store.cc',
'renderer/browser_plugin/browser_plugin_backing_store.h',
'renderer/browser_plugin/browser_plugin_bindings.cc',
'renderer/browser_plugin/browser_plugin_bindings.h',
'renderer/browser_plugin/browser_plugin_manager_factory.h',
......
......@@ -10,11 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner_helpers.h"
#if defined(OS_WIN)
#include "base/memory/shared_memory.h"
#endif
#include "base/values.h"
#include "content/renderer/browser_plugin/browser_plugin_backing_store.h"
#include "content/renderer/browser_plugin/browser_plugin_bindings.h"
#include "content/renderer/mouse_lock_dispatcher.h"
#include "content/renderer/render_view_impl.h"
......@@ -240,15 +236,7 @@ class CONTENT_EXPORT BrowserPlugin :
void TriggerEvent(const std::string& event_name,
std::map<std::string, base::Value*>* props);
// Creates and maps a shared damage buffer.
virtual base::SharedMemory* CreateDamageBuffer(
const size_t size,
base::SharedMemoryHandle* shared_memory_handle);
// Swaps out the |current_damage_buffer_| with the |pending_damage_buffer_|.
void SwapDamageBuffers();
// Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state and
// allocates a new |pending_damage_buffer_| if in software rendering mode.
// Populates BrowserPluginHostMsg_ResizeGuest_Params with resize state.
void PopulateResizeGuestParameters(
BrowserPluginHostMsg_ResizeGuest_Params* params,
const gfx::Rect& view_size,
......@@ -260,7 +248,7 @@ class CONTENT_EXPORT BrowserPlugin :
// Populates both AutoSize and ResizeGuest parameters based on the current
// autosize state.
void GetDamageBufferWithSizeParams(
void GetSizeParams(
BrowserPluginHostMsg_AutoSize_Params* auto_size_params,
BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params,
bool needs_repaint);
......@@ -268,15 +256,6 @@ class CONTENT_EXPORT BrowserPlugin :
// Informs the guest of an updated autosize state.
void UpdateGuestAutoSizeState(bool auto_size_enabled);
// Indicates whether a damage buffer was used by the guest process for the
// provided |params|.
static bool UsesDamageBuffer(
const BrowserPluginMsg_UpdateRect_Params& params);
// Indicates whether the |pending_damage_buffer_| was used to copy over pixels
// given the provided |params|.
bool UsesPendingDamageBuffer(
const BrowserPluginMsg_UpdateRect_Params& params);
// IPC message handlers.
// Please keep in alphabetical order.
......@@ -313,10 +292,6 @@ class CONTENT_EXPORT BrowserPlugin :
int render_view_routing_id_;
blink::WebPluginContainer* container_;
scoped_ptr<BrowserPluginBindings> bindings_;
scoped_ptr<BrowserPluginBackingStore> backing_store_;
scoped_ptr<base::SharedMemory> current_damage_buffer_;
scoped_ptr<base::SharedMemory> pending_damage_buffer_;
uint32 damage_buffer_sequence_id_;
bool paint_ack_received_;
gfx::Rect plugin_rect_;
float last_device_scale_factor_;
......@@ -351,7 +326,6 @@ class CONTENT_EXPORT BrowserPlugin :
scoped_refptr<BrowserPluginManager> browser_plugin_manager_;
// Used for HW compositing.
bool compositing_enabled_;
scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
// Used to identify the plugin to WebBindings.
......
// Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin_backing_store.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/vector2d_conversions.h"
#include "ui/surface/transport_dib.h"
namespace content {
// Max height and width for layers
static const int kMaxSize = 23170;
BrowserPluginBackingStore::BrowserPluginBackingStore(
const gfx::Size& size,
float scale_factor)
: size_(size),
scale_factor_(scale_factor) {
gfx::Size pixel_size = gfx::ToFlooredSize(gfx::ScaleSize(size, scale_factor));
bitmap_.setConfig(SkBitmap::kARGB_8888_Config,
pixel_size.width(), pixel_size.height());
bitmap_.allocPixels();
canvas_.reset(new SkCanvas(bitmap_));
}
BrowserPluginBackingStore::~BrowserPluginBackingStore() {
}
void BrowserPluginBackingStore::PaintToBackingStore(
const gfx::Rect& bitmap_rect,
const std::vector<gfx::Rect>& copy_rects,
void* bitmap) {
if (bitmap_rect.IsEmpty())
return;
gfx::Rect pixel_bitmap_rect = gfx::ToFlooredRectDeprecated(
gfx::ScaleRect(bitmap_rect, scale_factor_));
const int width = pixel_bitmap_rect.width();
const int height = pixel_bitmap_rect.height();
if (width <= 0 || width > kMaxSize ||
height <= 0 || height > kMaxSize)
return;
if (!bitmap)
return;
SkPaint copy_paint;
copy_paint.setXfermodeMode(SkXfermode::kSrc_Mode);
SkBitmap sk_bitmap;
sk_bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
sk_bitmap.setPixels(bitmap);
for (size_t i = 0; i < copy_rects.size(); i++) {
const gfx::Rect& pixel_copy_rect = gfx::ToEnclosingRect(
gfx::ScaleRect(copy_rects[i], scale_factor_));
int x = pixel_copy_rect.x() - pixel_bitmap_rect.x();
int y = pixel_copy_rect.y() - pixel_bitmap_rect.y();
SkIRect srcrect = SkIRect::MakeXYWH(x, y,
pixel_copy_rect.width(),
pixel_copy_rect.height());
SkRect dstrect = SkRect::MakeXYWH(
SkIntToScalar(pixel_copy_rect.x()),
SkIntToScalar(pixel_copy_rect.y()),
SkIntToScalar(pixel_copy_rect.width()),
SkIntToScalar(pixel_copy_rect.height()));
canvas_.get()->drawBitmapRect(sk_bitmap, &srcrect, dstrect, &copy_paint);
}
}
void BrowserPluginBackingStore::ScrollBackingStore(
const gfx::Vector2d& delta,
const gfx::Rect& clip_rect,
const gfx::Size& view_size) {
gfx::Rect pixel_rect = gfx::ToEnclosingRect(
gfx::ScaleRect(clip_rect, scale_factor_));
gfx::Vector2d pixel_delta = gfx::ToFlooredVector2d(
gfx::ScaleVector2d(delta, scale_factor_));
int x = std::min(pixel_rect.x(), pixel_rect.x() - pixel_delta.x());
int y = std::min(pixel_rect.y(), pixel_rect.y() - pixel_delta.y());
int w = pixel_rect.width() + abs(pixel_delta.x());
int h = pixel_rect.height() + abs(pixel_delta.y());
SkIRect rect = SkIRect::MakeXYWH(x, y, w, h);
bitmap_.scrollRect(&rect, pixel_delta.x(), pixel_delta.y());
}
void BrowserPluginBackingStore::Clear(SkColor clear_color) {
canvas_->clear(clear_color);
}
} // namespace content
// Copyright (c) 2012 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.
#ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BACKING_STORE_H__
#define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BACKING_STORE_H__
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/size.h"
#include "ui/gfx/vector2d.h"
class SkCanvas;
class TransportDIB;
namespace gfx {
class Canvas;
class Point;
class Rect;
}
namespace content {
// The BrowserPluginBackingStore is a wrapper around an SkBitmap that is used
// in the software rendering path of the browser plugin. The backing store has
// two write operations:
// 1. PaintToBackingStore copies pixel regions to the bitmap.
// 2. ScrollBackingStore scrolls a region of the bitmap by dx, and dy.
// These are called in response to changes in the guest relayed via
// BrowserPluginMsg_UpdateRect. See BrowserPlugin::UpdateRect.
class BrowserPluginBackingStore {
public:
BrowserPluginBackingStore(const gfx::Size& size, float scale_factor);
virtual ~BrowserPluginBackingStore();
void PaintToBackingStore(
const gfx::Rect& bitmap_rect,
const std::vector<gfx::Rect>& copy_rects,
void* bitmap);
void ScrollBackingStore(const gfx::Vector2d& delta,
const gfx::Rect& clip_rect,
const gfx::Size& view_size);
void Clear(SkColor clear_color);
const gfx::Size& GetSize() const { return size_; }
const SkBitmap& GetBitmap() const { return bitmap_; }
float GetScaleFactor() const { return scale_factor_; }
private:
gfx::Size size_;
SkBitmap bitmap_;
scoped_ptr<SkCanvas> canvas_;
float scale_factor_;
DISALLOW_COPY_AND_ASSIGN(BrowserPluginBackingStore);
};
} // namespace content
#endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_BACKING_STORE_H__
......@@ -192,11 +192,7 @@ MockBrowserPlugin* BrowserPluginTest::GetCurrentPluginWithAttachParams(
}
// This test verifies that an initial resize occurs when we instantiate the
// browser plugin. This test also verifies that the browser plugin is waiting
// for a BrowserPluginMsg_UpdateRect in response. We issue an UpdateRect, and
// we observe an UpdateRect_ACK, with the |pending_damage_buffer_| reset,
// indiciating that the BrowserPlugin is not waiting for any more UpdateRects to
// satisfy its resize request.
// browser plugin.
TEST_F(BrowserPluginTest, InitialResize) {
LoadHTML(GetHTMLForBrowserPluginObject().c_str());
// Verify that the information in Attach is correct.
......@@ -206,22 +202,6 @@ TEST_F(BrowserPluginTest, InitialResize) {
EXPECT_EQ(640, params.resize_guest_params.view_rect.width());
EXPECT_EQ(480, params.resize_guest_params.view_rect.height());
ASSERT_TRUE(browser_plugin);
// Now the browser plugin is expecting a UpdateRect resize.
int instance_id = browser_plugin->guest_instance_id();
EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
// Send the BrowserPlugin an UpdateRect equal to its container size with
// the same damage buffer. That should clear |pending_damage_buffer_|.
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.damage_buffer_sequence_id =
browser_plugin->damage_buffer_sequence_id_;
update_rect_params.view_size = gfx::Size(640, 480);
update_rect_params.scale_factor = 1.0f;
update_rect_params.is_resize_ack = true;
update_rect_params.needs_ack = true;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
}
// This test verifies that all attributes (present at the time of writing) are
......@@ -305,24 +285,16 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
MockBrowserPlugin* browser_plugin = GetCurrentPlugin();
ASSERT_TRUE(browser_plugin);
int instance_id = browser_plugin->guest_instance_id();
EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
// Send an UpdateRect to the BrowserPlugin to make it use the pending damage
// buffer.
// Send an UpdateRect to the BrowserPlugin to make sure the browser sees a
// resize related (SetAutoSize) message.
{
// We send a stale UpdateRect to the BrowserPlugin.
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.view_size = gfx::Size(640, 480);
update_rect_params.scale_factor = 1.0f;
update_rect_params.is_resize_ack = true;
update_rect_params.needs_ack = true;
// By sending |damage_buffer_sequence_id| back to BrowserPlugin on
// UpdateRect, then the BrowserPlugin knows that the browser process has
// received and has begun to use the |pending_damage_buffer_|.
update_rect_params.damage_buffer_sequence_id =
browser_plugin->damage_buffer_sequence_id_;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
EXPECT_EQ(NULL, browser_plugin->pending_damage_buffer_.get());
}
browser_plugin_manager()->sink().ClearMessages();
......@@ -360,9 +332,6 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
BrowserPluginHostMsg_ResizeGuest::Read(msg, &instance_id, &params);
EXPECT_EQ(641, params.view_rect.width());
EXPECT_EQ(480, params.view_rect.height());
// This indicates that the BrowserPlugin has sent out a previous resize
// request but has not yet received an UpdateRect for that request.
EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
{
// We send a stale UpdateRect to the BrowserPlugin.
......@@ -370,14 +339,8 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
update_rect_params.view_size = gfx::Size(641, 480);
update_rect_params.scale_factor = 1.0f;
update_rect_params.is_resize_ack = true;
update_rect_params.needs_ack = true;
update_rect_params.damage_buffer_sequence_id =
browser_plugin->damage_buffer_sequence_id_;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
// This tells us that the BrowserPlugin is still expecting another
// UpdateRect with the most recent size.
EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
}
// Send the BrowserPlugin another UpdateRect, but this time with a size
// that matches the size of the container.
......@@ -386,14 +349,8 @@ TEST_F(BrowserPluginTest, ResizeFlowControl) {
update_rect_params.view_size = gfx::Size(643, 480);
update_rect_params.scale_factor = 1.0f;
update_rect_params.is_resize_ack = true;
update_rect_params.needs_ack = true;
update_rect_params.damage_buffer_sequence_id =
browser_plugin->damage_buffer_sequence_id_;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
// The BrowserPlugin has finally received an UpdateRect that satisifes
// its current size, and so it is happy.
EXPECT_FALSE(browser_plugin->pending_damage_buffer_.get());
}
}
......@@ -594,9 +551,6 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
EXPECT_EQ(1337, params.auto_size_params.max_size.width());
EXPECT_EQ(1338, params.auto_size_params.max_size.height());
// Verify that we are waiting for the browser process to grab the new
// damage buffer.
EXPECT_TRUE(browser_plugin->pending_damage_buffer_.get());
// Disable autosize. AutoSize state will not be sent to the guest until
// the guest has responded to the last resize request.
ExecuteJavaScript(kDisableAutoSize);
......@@ -607,32 +561,28 @@ TEST_F(BrowserPluginTest, AutoSizeAttributes) {
BrowserPluginHostMsg_SetAutoSize::ID);
EXPECT_FALSE(auto_size_msg);
// Send the BrowserPlugin an UpdateRect equal to its |max_size| with
// the same damage buffer.
// Send the BrowserPlugin an UpdateRect equal to its |max_size|.
BrowserPluginMsg_UpdateRect_Params update_rect_params;
update_rect_params.damage_buffer_sequence_id =
browser_plugin->damage_buffer_sequence_id_;
update_rect_params.view_size = gfx::Size(1337, 1338);
update_rect_params.scale_factor = 1.0f;
update_rect_params.is_resize_ack = true;
update_rect_params.needs_ack = true;
BrowserPluginMsg_UpdateRect msg(instance_id, update_rect_params);
browser_plugin->OnMessageReceived(msg);
// Verify that the autosize state has been updated.
{
const IPC::Message* auto_size_msg =
browser_plugin_manager()->sink().GetUniqueMessageMatching(
BrowserPluginHostMsg_UpdateRect_ACK::ID);
browser_plugin_manager()->sink().GetUniqueMessageMatching(
BrowserPluginHostMsg_SetAutoSize::ID);
ASSERT_TRUE(auto_size_msg);
int instance_id = 0;
BrowserPluginHostMsg_AutoSize_Params auto_size_params;
BrowserPluginHostMsg_ResizeGuest_Params resize_params;
BrowserPluginHostMsg_UpdateRect_ACK::Read(auto_size_msg,
&instance_id,
&auto_size_params,
&resize_params);
BrowserPluginHostMsg_SetAutoSize::Read(auto_size_msg,
&instance_id,
&auto_size_params,
&resize_params);
EXPECT_FALSE(auto_size_params.enable);
// These value are not populated (as an optimization) if autosize is
// disabled.
......
......@@ -20,8 +20,6 @@ class MockBrowserPlugin : public BrowserPlugin {
// Allow poking at a few private members.
using BrowserPlugin::OnAttachACK;
using BrowserPlugin::guest_crashed_;
using BrowserPlugin::pending_damage_buffer_;
using BrowserPlugin::damage_buffer_sequence_id_;
};
} // namespace content
......
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