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 "chrome/browser/renderer_host/backing_store.h" | 5 #include "chrome/browser/renderer_host/backing_store.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <sys/ipc.h> | 8 #include <sys/ipc.h> |
9 #include <sys/shm.h> | 9 #include <sys/shm.h> |
| 10 #if defined(TOOLKIT_GTK) |
| 11 #include <cairo-xlib.h> |
| 12 #include <gtk/gtk.h> |
| 13 #endif |
10 | 14 |
11 #include <algorithm> | 15 #include <algorithm> |
12 #include <utility> | 16 #include <utility> |
13 | 17 |
14 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
15 #include "base/histogram.h" | 19 #include "base/histogram.h" |
16 #include "base/logging.h" | 20 #include "base/logging.h" |
17 #include "base/time.h" | 21 #include "base/time.h" |
18 #include "chrome/common/transport_dib.h" | 22 #include "chrome/common/transport_dib.h" |
19 #include "chrome/common/x11_util.h" | 23 #include "chrome/common/x11_util.h" |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 333 |
330 PaintRect(process, bitmap, bitmap_rect); | 334 PaintRect(process, bitmap, bitmap_rect); |
331 } | 335 } |
332 | 336 |
333 void BackingStore::ShowRect(const gfx::Rect& rect, XID target) { | 337 void BackingStore::ShowRect(const gfx::Rect& rect, XID target) { |
334 XCopyArea(display_, pixmap_, target, static_cast<GC>(pixmap_gc_), | 338 XCopyArea(display_, pixmap_, target, static_cast<GC>(pixmap_gc_), |
335 rect.x(), rect.y(), rect.width(), rect.height(), | 339 rect.x(), rect.y(), rect.width(), rect.height(), |
336 rect.x(), rect.y()); | 340 rect.x(), rect.y()); |
337 } | 341 } |
338 | 342 |
| 343 #if defined(TOOLKIT_GTK) |
| 344 void BackingStore::PaintToRect(const gfx::Rect& rect, GdkDrawable* target) { |
| 345 cairo_surface_t* surface = cairo_xlib_surface_create( |
| 346 display_, pixmap_, static_cast<Visual*>(visual_), |
| 347 size_.width(), size_.height()); |
| 348 cairo_t* cr = gdk_cairo_create(target); |
| 349 |
| 350 cairo_translate(cr, rect.x(), rect.y()); |
| 351 double x_scale = static_cast<double>(rect.width()) / size_.width(); |
| 352 double y_scale = static_cast<double>(rect.height()) / size_.height(); |
| 353 cairo_scale(cr, x_scale, y_scale); |
| 354 |
| 355 cairo_pattern_t* pattern = cairo_pattern_create_for_surface(surface); |
| 356 cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST); |
| 357 cairo_set_source(cr, pattern); |
| 358 cairo_pattern_destroy(pattern); |
| 359 |
| 360 cairo_identity_matrix(cr); |
| 361 |
| 362 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); |
| 363 cairo_fill(cr); |
| 364 cairo_destroy(cr); |
| 365 } |
| 366 #endif |
| 367 |
339 SkBitmap BackingStore::PaintRectToBitmap(const gfx::Rect& rect) { | 368 SkBitmap BackingStore::PaintRectToBitmap(const gfx::Rect& rect) { |
340 base::TimeTicks begin_time = base::TimeTicks::Now(); | 369 base::TimeTicks begin_time = base::TimeTicks::Now(); |
341 const int width = std::min(size_.width(), rect.width()); | 370 const int width = std::min(size_.width(), rect.width()); |
342 const int height = std::min(size_.height(), rect.height()); | 371 const int height = std::min(size_.height(), rect.height()); |
343 | 372 |
344 XImage* image; | 373 XImage* image; |
345 XShmSegmentInfo shminfo; // Used only when shared memory is enabled. | 374 XShmSegmentInfo shminfo; // Used only when shared memory is enabled. |
346 if (use_shared_memory_) { | 375 if (use_shared_memory_) { |
347 // Use shared memory for faster copies when it's available. | 376 // Use shared memory for faster copies when it's available. |
348 Visual* visual = static_cast<Visual*>(visual_); | 377 Visual* visual = static_cast<Visual*>(visual_); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 | 430 |
402 if (use_shared_memory_) | 431 if (use_shared_memory_) |
403 DestroySharedImage(display_, image, &shminfo); | 432 DestroySharedImage(display_, image, &shminfo); |
404 else | 433 else |
405 XFree(image); | 434 XFree(image); |
406 | 435 |
407 HISTOGRAM_TIMES("BackingStore.RetrievalFromX", | 436 HISTOGRAM_TIMES("BackingStore.RetrievalFromX", |
408 base::TimeTicks::Now() - begin_time); | 437 base::TimeTicks::Now() - begin_time); |
409 return bitmap; | 438 return bitmap; |
410 } | 439 } |
OLD | NEW |