OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_x.h" | 5 #include "chrome/browser/renderer_host/backing_store_x.h" |
6 | 6 |
7 #include <cairo-xlib.h> | 7 #include <cairo-xlib.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <sys/ipc.h> | 10 #include <sys/ipc.h> |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 } | 319 } |
320 } else { | 320 } else { |
321 // Non-shared memory case just copy the image from the server. | 321 // Non-shared memory case just copy the image from the server. |
322 image = XGetImage(display_, pixmap_, | 322 image = XGetImage(display_, pixmap_, |
323 rect.x(), rect.y(), width, height, | 323 rect.x(), rect.y(), width, height, |
324 AllPlanes, ZPixmap); | 324 AllPlanes, ZPixmap); |
325 } | 325 } |
326 | 326 |
327 // TODO(jhawkins): Need to convert the image data if the image bits per pixel | 327 // TODO(jhawkins): Need to convert the image data if the image bits per pixel |
328 // is not 32. | 328 // is not 32. |
| 329 // Note that this also initializes the output bitmap as opaque. |
329 if (!output->initialize(width, height, true) || | 330 if (!output->initialize(width, height, true) || |
330 image->bits_per_pixel != 32) { | 331 image->bits_per_pixel != 32) { |
331 if (shared_memory_support_ != x11_util::SHARED_MEMORY_NONE) | 332 if (shared_memory_support_ != x11_util::SHARED_MEMORY_NONE) |
332 DestroySharedImage(display_, image, &shminfo); | 333 DestroySharedImage(display_, image, &shminfo); |
333 else | 334 else |
334 XDestroyImage(image); | 335 XDestroyImage(image); |
335 return false; | 336 return false; |
336 } | 337 } |
337 | 338 |
338 // The X image might have a different row stride, so iterate through it and | 339 // The X image might have a different row stride, so iterate through |
339 // copy each row out, only up to the pixels we're actually using. | 340 // it and copy each row out, only up to the pixels we're actually |
340 // This code assumes a visual mode where a pixel is represented using | 341 // using. This code assumes a visual mode where a pixel is |
341 // a byte for each component. | 342 // represented using a 32-bit unsigned int, with a byte per component. |
342 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); | 343 SkBitmap bitmap = output->getTopPlatformDevice().accessBitmap(true); |
343 for (int y = 0; y < height; y++) { | 344 for (int y = 0; y < height; y++) { |
| 345 const uint32* src_row = reinterpret_cast<uint32*>( |
| 346 &image->data[image->bytes_per_line * y]); |
344 uint32* dest_row = bitmap.getAddr32(0, y); | 347 uint32* dest_row = bitmap.getAddr32(0, y); |
345 const char* src_row = &image->data[image->bytes_per_line * y]; | 348 for (int x = 0; x < width; ++x, ++dest_row) { |
346 memcpy(dest_row, src_row, width * 4); | 349 // Force alpha to be 0xff, because otherwise it causes rendering problems. |
| 350 *dest_row = src_row[x] | 0xff000000; |
| 351 } |
347 } | 352 } |
348 | 353 |
349 if (shared_memory_support_ != x11_util::SHARED_MEMORY_NONE) | 354 if (shared_memory_support_ != x11_util::SHARED_MEMORY_NONE) |
350 DestroySharedImage(display_, image, &shminfo); | 355 DestroySharedImage(display_, image, &shminfo); |
351 else | 356 else |
352 XDestroyImage(image); | 357 XDestroyImage(image); |
353 | 358 |
354 HISTOGRAM_TIMES("BackingStore.RetrievalFromX", | 359 HISTOGRAM_TIMES("BackingStore.RetrievalFromX", |
355 base::TimeTicks::Now() - begin_time); | 360 base::TimeTicks::Now() - begin_time); |
356 return true; | 361 return true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 cairo_set_source(cr, pattern); | 432 cairo_set_source(cr, pattern); |
428 cairo_pattern_destroy(pattern); | 433 cairo_pattern_destroy(pattern); |
429 | 434 |
430 cairo_identity_matrix(cr); | 435 cairo_identity_matrix(cr); |
431 | 436 |
432 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); | 437 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); |
433 cairo_fill(cr); | 438 cairo_fill(cr); |
434 cairo_destroy(cr); | 439 cairo_destroy(cr); |
435 } | 440 } |
436 #endif | 441 #endif |
OLD | NEW |