diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 02:11:48 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-03 02:11:48 +0000 |
commit | 661eb9d1aa5468b984a92e66937432d881f70427 (patch) | |
tree | 81bf2b132ac6c7b05b04598e875552819222bb73 /chrome/renderer/render_widget.cc | |
parent | 99aa2dbf4962fb1a4a52a3eae9bb51ad3113b7be (diff) | |
download | chromium_src-661eb9d1aa5468b984a92e66937432d881f70427.zip chromium_src-661eb9d1aa5468b984a92e66937432d881f70427.tar.gz chromium_src-661eb9d1aa5468b984a92e66937432d881f70427.tar.bz2 |
From agl. Cleaned up version of issue 19046.
POSIX: bitmap data on the wire
On Windows, when drawing a given rect in the renderer, we allocate memory for the bitmap, render and send a shared memory handle across IPC. In the browser, we bitblit the shared memory to the backing store and draw it to the screen.
In the long term, on Linux, we want the backingstore to be shared with both X and the renderer. The renderer then draws directly to that store, sends an IPC to the browser and the browser sends a message to X to bitblit to the display. Since only cache a few backing stores we'll need messages from the browser to tell the renderer to attach and detatch from shared memory regions as they get created and evicted.
In the short term, however, to get something that works, we make a BitmapWireData typedef. This will be a shared memory region on Windows, as before, and on POSIX we'll be sending the bitmap data over the wire. Obviously this'll be pretty slow but it'll work sooner.
Review URL: http://codereview.chromium.org/19491
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_widget.cc')
-rw-r--r-- | chrome/renderer/render_widget.cc | 66 |
1 files changed, 52 insertions, 14 deletions
diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index 587c517..1e14993 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -9,8 +9,14 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/scoped_ptr.h" +#include "build/build_config.h" #include "chrome/renderer/render_process.h" -#include "skia/ext/platform_canvas_win.h" +#include "skia/ext/platform_canvas.h" + +#if defined(OS_POSIX) +#include "skia/include/SkPixelRef.h" +#include "skia/include/SkMallocPixelRef.h" +#endif // defined(OS_POSIX) #include "webkit/glue/webinputevent.h" #include "webkit/glue/webwidget.h" @@ -77,10 +83,10 @@ RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) next_paint_flags_(0), paint_reply_pending_(false), did_show_(false), - closing_(false), is_hidden_(false), needs_repainting_on_restore_(false), has_focus_(false), + closing_(false), ime_is_active_(false), ime_control_enable_ime_(true), ime_control_x_(-1), @@ -352,25 +358,25 @@ void RenderWidget::ClearFocus() { } void RenderWidget::PaintRect(const gfx::Rect& rect, - base::SharedMemory* paint_buf) { - skia::PlatformCanvasWin canvas(rect.width(), rect.height(), true, - paint_buf->handle()); + skia::PlatformCanvas* canvas) { // Bring the canvas into the coordinate system of the paint rect - canvas.translate(static_cast<SkScalar>(-rect.x()), - static_cast<SkScalar>(-rect.y())); + canvas->translate(static_cast<SkScalar>(-rect.x()), + static_cast<SkScalar>(-rect.y())); - webwidget_->Paint(&canvas, rect); + webwidget_->Paint(canvas, rect); // Flush to underlying bitmap. TODO(darin): is this needed? - canvas.getTopPlatformDevice().accessBitmap(false); + canvas->getTopPlatformDevice().accessBitmap(false); // Let the subclass observe this paint operations. DidPaint(); } +// static size_t RenderWidget::GetPaintBufSize(const gfx::Rect& rect) { // TODO(darin): protect against overflow - return 4 * rect.width() * rect.height(); + const size_t stride = skia::PlatformCanvas::StrideForWidth(rect.width()); + return stride * rect.height(); } void RenderWidget::DoDeferredPaint() { @@ -394,22 +400,38 @@ void RenderWidget::DoDeferredPaint() { paint_rect_ = gfx::Rect(); // Compute a buffer for painting and cache it. +#if defined(OS_WIN) current_paint_buf_ = RenderProcess::AllocSharedMemory(GetPaintBufSize(damaged_rect)); if (!current_paint_buf_) { NOTREACHED(); return; } + skia::PlatformCanvasWin canvas(damaged_rect.width(), damaged_rect.height(), + true, current_paint_buf_->handle()); +#elif defined(OS_POSIX) + // Currently, on POSIX, we are serialising the bitmap data over the IPC + // channel. + skia::PlatformCanvas canvas(damaged_rect.width(), damaged_rect.height(), + true); +#endif // defined(OS_POSIX) - PaintRect(damaged_rect, current_paint_buf_); + PaintRect(damaged_rect, &canvas); ViewHostMsg_PaintRect_Params params; - params.bitmap = current_paint_buf_->handle(); params.bitmap_rect = damaged_rect; params.view_size = size_; params.plugin_window_moves = plugin_window_moves_; params.flags = next_paint_flags_; +#if defined(OS_WIN) + // Windows passes a HANDLE to the shared memory over IPC + params.bitmap = current_paint_buf_->handle(); +#elif defined(OS_POSIX) + // POSIX currently passes the data itself. + params.bitmap = canvas.getDevice()->accessBitmap(false); +#endif // defined(OS_WIN) + plugin_window_moves_.clear(); paint_reply_pending_ = true; @@ -469,17 +491,25 @@ void RenderWidget::DoDeferredScroll() { // In case the scroll offset exceeds the width/height of the scroll rect damaged_rect = scroll_rect_.Intersect(damaged_rect); +#if defined(OS_WIN) current_scroll_buf_ = RenderProcess::AllocSharedMemory(GetPaintBufSize(damaged_rect)); if (!current_scroll_buf_) { NOTREACHED(); return; } + skia::PlatformCanvasWin canvas(damaged_rect.width(), damaged_rect.height(), + true, current_scroll_buf_->handle()); +#elif defined(OS_POSIX) + // Currently, on POSIX, we are serialising the bitmap data over the IPC + // channel. + skia::PlatformCanvas canvas(damaged_rect.width(), damaged_rect.height(), + true); +#endif // defined(OS_POSIX) // Set these parameters before calling Paint, since that could result in // further invalidates (uncommon). ViewHostMsg_ScrollRect_Params params; - params.bitmap = current_scroll_buf_->handle(); params.bitmap_rect = damaged_rect; params.dx = scroll_delta_.x(); params.dy = scroll_delta_.y(); @@ -487,12 +517,20 @@ void RenderWidget::DoDeferredScroll() { params.view_size = size_; params.plugin_window_moves = plugin_window_moves_; +#if defined(OS_WIN) + // Windows passes a HANDLE to the shared memory over IPC + params.bitmap = current_scroll_buf_->handle(); +#elif defined(OS_POSIX) + // POSIX currently passes the data itself. + params.bitmap = canvas.getDevice()->accessBitmap(false); +#endif // defined(OS_WIN) + plugin_window_moves_.clear(); // Mark the scroll operation as no longer pending. scroll_rect_ = gfx::Rect(); - PaintRect(damaged_rect, current_scroll_buf_); + PaintRect(damaged_rect, &canvas); Send(new ViewHostMsg_ScrollRect(routing_id_, params)); UpdateIME(); } |