Stop render_widget from polling WebWiget's isAcceleratedCompositingActive.
Replace this with an implementation of the
WebWidgetClient:: didActivateAcceleratedCompositing.

BUG=none
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66691 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc
index 9d32655..bcf58b0a 100644
--- a/chrome/renderer/render_widget.cc
+++ b/chrome/renderer/render_widget.cc
@@ -75,7 +75,7 @@
       popup_type_(popup_type),
       pending_window_rect_count_(0),
       suppress_next_char_events_(false),
-      is_gpu_rendering_active_(false) {
+      is_accelerated_compositing_active_(false) {
   RenderProcess::current()->AddRefProcess();
   DCHECK(render_thread_);
 }
@@ -246,7 +246,7 @@
   // an ACK if we are resized to a non-empty rect.
   webwidget_->resize(new_size);
   if (!new_size.IsEmpty()) {
-    if (!webwidget_->isAcceleratedCompositingActive()) {
+    if (!is_accelerated_compositing_active_) {
       // Resize should have caused an invalidation of the entire view.
       DCHECK(paint_aggregator_.HasPendingUpdate());
     }
@@ -278,7 +278,7 @@
   set_next_paint_is_restore_ack();
 
   // Generate a full repaint.
-  if (!webwidget_->isAcceleratedCompositingActive()) {
+  if (!is_accelerated_compositing_active_) {
     didInvalidateRect(gfx::Rect(size_.width(), size_.height()));
   } else {
     scheduleComposite();
@@ -465,21 +465,6 @@
   // GpuRenderingActivated message.
   webwidget_->layout();
 
-  // If we are using accelerated compositing then all the drawing
-  // to the associated window happens directly from the gpu process and the
-  // browser process shouldn't do any drawing.
-  // TODO(vangelis): Currently the accelerated compositing path relies on
-  // invalidating parts of the page so that we get a request to redraw.
-  // This needs to change to a model where the compositor updates the
-  // contents of the page independently and the browser process gets no
-  // longer involved.
-  if (webwidget_->isAcceleratedCompositingActive() !=
-      is_gpu_rendering_active_) {
-    is_gpu_rendering_active_ = webwidget_->isAcceleratedCompositingActive();
-    Send(new ViewHostMsg_GpuRenderingActivated(
-        routing_id_, is_gpu_rendering_active_));
-  }
-
   // OK, save the pending update to a local since painting may cause more
   // invalidation.  Some WebCore rendering objects only layout when painted.
   PaintAggregator::PendingUpdate update = paint_aggregator_.GetPendingUpdate();
@@ -495,13 +480,13 @@
   std::vector<gfx::Rect> copy_rects;
   gfx::Rect optimized_copy_rect, optimized_copy_location;
   if (update.scroll_rect.IsEmpty() &&
-      !is_gpu_rendering_active_ &&
+      !is_accelerated_compositing_active_ &&
       GetBitmapForOptimizedPluginPaint(bounds, &dib, &optimized_copy_location,
                                        &optimized_copy_rect)) {
     bounds = optimized_copy_location;
     copy_rects.push_back(optimized_copy_rect);
     dib_id = dib->id();
-  } else if (!is_gpu_rendering_active_) {
+  } else if (!is_accelerated_compositing_active_) {
     // Compute a buffer for painting and cache it.
     scoped_ptr<skia::PlatformCanvas> canvas(
         RenderProcess::current()->GetDrawingCanvas(&current_paint_buf_,
@@ -548,7 +533,7 @@
   params.bitmap_rect = bounds;
   params.dx = update.scroll_delta.x();
   params.dy = update.scroll_delta.y();
-  if (is_gpu_rendering_active_) {
+  if (is_accelerated_compositing_active_) {
     // If painting is done via the gpu process then we clear out all damage
     // rects to save the browser process from doing unecessary work.
     params.scroll_rect = gfx::Rect();
@@ -576,15 +561,8 @@
 // WebWidgetClient
 
 void RenderWidget::didInvalidateRect(const WebRect& rect) {
-  if (webwidget_->isAcceleratedCompositingActive()) {
-    // Drop invalidates on the floor when we are in compositing mode.
-    // TODO(nduca): Stop WebViewImpl from sending invalidates in the first
-    // place.
-    if (!(rect.x == 0 && rect.y == 0 &&
-          rect.width == 1 && rect.height == 1)) {
-      return;
-    }
-  }
+  DCHECK(!is_accelerated_compositing_active_ ||
+    (rect.x == 0 && rect.y == 0 && rect.width == 1 && rect.height == 1));
 
   // We only want one pending DoDeferredUpdate call at any time...
   bool update_pending = paint_aggregator_.HasPendingUpdate();
@@ -617,7 +595,7 @@
 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) {
   // Drop scrolls on the floor when we are in compositing mode.
   // TODO(nduca): stop WebViewImpl from sending scrolls in the first place.
-  if (webwidget_->isAcceleratedCompositingActive())
+  if (is_accelerated_compositing_active_)
     return;
 
   // We only want one pending DoDeferredUpdate call at any time...
@@ -648,6 +626,12 @@
       this, &RenderWidget::CallDoDeferredUpdate));
 }
 
+void RenderWidget::didActivateAcceleratedCompositing(bool active) {
+  is_accelerated_compositing_active_ = active;
+  Send(new ViewHostMsg_GpuRenderingActivated(
+    routing_id_, is_accelerated_compositing_active_));
+}
+
 void RenderWidget::scheduleComposite() {
   // TODO(nduca): replace with something a little less hacky.  The reason this
   // hack is still used is because the Invalidate-DoDeferredUpdate loop
@@ -874,7 +858,7 @@
     return;
 
   set_next_paint_is_repaint_ack();
-  if (webwidget_->isAcceleratedCompositingActive()) {
+  if (is_accelerated_compositing_active_) {
     scheduleComposite();
   } else {
     gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());