| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/tools/test_shell/webwidget_host.h" | 5 #include "webkit/tools/test_shell/webwidget_host.h" |
| 6 | 6 |
| 7 #include <cairo/cairo.h> | 7 #include <cairo/cairo.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 } | 271 } |
| 272 | 272 |
| 273 void WebWidgetHost::Resize(const gfx::Size &newsize) { | 273 void WebWidgetHost::Resize(const gfx::Size &newsize) { |
| 274 // The pixel buffer backing us is now the wrong size | 274 // The pixel buffer backing us is now the wrong size |
| 275 canvas_.reset(); | 275 canvas_.reset(); |
| 276 | 276 |
| 277 webwidget_->Resize(gfx::Size(newsize.width(), newsize.height())); | 277 webwidget_->Resize(gfx::Size(newsize.width(), newsize.height())); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void WebWidgetHost::Paint() { | 280 void WebWidgetHost::Paint() { |
| 281 PaintToCanvas(); |
| 282 PaintCanvasToView(); |
| 283 } |
| 284 |
| 285 void WebWidgetHost::PaintToCanvas() { |
| 281 int width = view_->allocation.width; | 286 int width = view_->allocation.width; |
| 282 int height = view_->allocation.height; | 287 int height = view_->allocation.height; |
| 283 gfx::Rect client_rect(width, height); | 288 gfx::Rect client_rect(width, height); |
| 284 | 289 |
| 285 // Allocate a canvas if necessary | 290 // Allocate a canvas if necessary |
| 286 if (!canvas_.get()) { | 291 if (!canvas_.get()) { |
| 287 ResetScrollRect(); | 292 ResetScrollRect(); |
| 288 paint_rect_ = client_rect; | 293 paint_rect_ = client_rect; |
| 289 canvas_.reset(new skia::PlatformCanvas(width, height, true)); | 294 canvas_.reset(new skia::PlatformCanvas(width, height, true)); |
| 290 if (!canvas_.get()) { | 295 if (!canvas_.get()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 309 gfx::Rect rect(paint_rect_); | 314 gfx::Rect rect(paint_rect_); |
| 310 paint_rect_ = gfx::Rect(); | 315 paint_rect_ = gfx::Rect(); |
| 311 | 316 |
| 312 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; | 317 DLOG_IF(WARNING, i == 1) << "painting caused additional invalidations"; |
| 313 PaintRect(rect); | 318 PaintRect(rect); |
| 314 total_paint = total_paint.Union(rect); | 319 total_paint = total_paint.Union(rect); |
| 315 } | 320 } |
| 316 } | 321 } |
| 317 DCHECK(paint_rect_.IsEmpty()); | 322 DCHECK(paint_rect_.IsEmpty()); |
| 318 | 323 |
| 324 } |
| 325 |
| 326 void WebWidgetHost::PaintCanvasToView() { |
| 319 // Invalidate the paint region on the widget's underlying gdk window. Note | 327 // Invalidate the paint region on the widget's underlying gdk window. Note |
| 320 // that gdk_window_invalidate_* will generate extra expose events, which | 328 // that gdk_window_invalidate_* will generate extra expose events, which |
| 321 // we wish to avoid. So instead we use calls to begin_paint/end_paint. | 329 // we wish to avoid. So instead we use calls to begin_paint/end_paint. |
| 322 GdkRectangle grect = { | 330 GdkRectangle grect = { |
| 323 total_paint.x(), | 331 0, |
| 324 total_paint.y(), | 332 0, |
| 325 total_paint.width(), | 333 canvas_->width(), |
| 326 total_paint.height(), | 334 canvas_->height(), |
| 327 }; | 335 }; |
| 328 GdkWindow* window = view_->window; | 336 GdkWindow* window = view_->window; |
| 329 gdk_window_begin_paint_rect(window, &grect); | 337 gdk_window_begin_paint_rect(window, &grect); |
| 330 | 338 |
| 331 // BitBlit to the gdk window. | 339 // BitBlit to the gdk window. |
| 332 skia::PlatformDeviceLinux &platdev = canvas_->getTopPlatformDevice(); | 340 skia::PlatformDeviceLinux &platdev = canvas_->getTopPlatformDevice(); |
| 333 skia::BitmapPlatformDeviceLinux* const bitdev = | 341 skia::BitmapPlatformDeviceLinux* const bitdev = |
| 334 static_cast<skia::BitmapPlatformDeviceLinux* >(&platdev); | 342 static_cast<skia::BitmapPlatformDeviceLinux* >(&platdev); |
| 335 cairo_t* cairo_drawable = gdk_cairo_create(window); | 343 cairo_t* cairo_drawable = gdk_cairo_create(window); |
| 336 cairo_set_source_surface(cairo_drawable, bitdev->surface(), 0, 0); | 344 cairo_set_source_surface(cairo_drawable, bitdev->surface(), 0, 0); |
| 337 cairo_paint(cairo_drawable); | 345 cairo_paint(cairo_drawable); |
| 338 cairo_destroy(cairo_drawable); | 346 cairo_destroy(cairo_drawable); |
| 339 | 347 |
| 340 gdk_window_end_paint(window); | 348 gdk_window_end_paint(window); |
| 341 } | 349 } |
| 342 | 350 |
| 351 void WebWidgetHost::DisplayForRepaint() { |
| 352 PaintToCanvas(); |
| 353 |
| 354 // Paint a gray mask over everything for the repaint Layout tests. |
| 355 const SkColor kMaskColor = SkColorSetARGB(168, 0, 0, 0); // alpha=0.66 |
| 356 canvas_->drawColor(kMaskColor, SkPorterDuff::kSrcOver_Mode); |
| 357 |
| 358 PaintCanvasToView(); |
| 359 } |
| 360 |
| 343 void WebWidgetHost::ResetScrollRect() { | 361 void WebWidgetHost::ResetScrollRect() { |
| 344 // This method is only needed for optimized scroll painting, which we don't | 362 // This method is only needed for optimized scroll painting, which we don't |
| 345 // care about in the test shell, yet. | 363 // care about in the test shell, yet. |
| 346 } | 364 } |
| 347 | 365 |
| 348 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { | 366 void WebWidgetHost::PaintRect(const gfx::Rect& rect) { |
| 349 set_painting(true); | 367 set_painting(true); |
| 350 webwidget_->Paint(canvas_.get(), rect); | 368 webwidget_->Paint(canvas_.get(), rect); |
| 351 set_painting(false); | 369 set_painting(false); |
| 352 } | 370 } |
| 353 | 371 |
| 354 void WebWidgetHost::WindowDestroyed() { | 372 void WebWidgetHost::WindowDestroyed() { |
| 355 delete this; | 373 delete this; |
| 356 } | 374 } |
| OLD | NEW |