OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/backing_store_gtk.h" | 5 #include "content/browser/renderer_host/backing_store_gtk.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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 } | 492 } |
493 | 493 |
494 if (*scheduled_completion_callback == false) { | 494 if (*scheduled_completion_callback == false) { |
495 // If we didn't schedule a callback, we need to delete our resources now. | 495 // If we didn't schedule a callback, we need to delete our resources now. |
496 XRenderFreePicture(display_, picture); | 496 XRenderFreePicture(display_, picture); |
497 XFreePixmap(display_, pixmap); | 497 XFreePixmap(display_, pixmap); |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 bool BackingStoreGtk::CopyFromBackingStore(const gfx::Rect& rect, | 501 bool BackingStoreGtk::CopyFromBackingStore(const gfx::Rect& rect, |
502 skia::PlatformCanvas* output) { | 502 skia::PlatformBitmap* output) { |
503 base::TimeTicks begin_time = base::TimeTicks::Now(); | 503 base::TimeTicks begin_time = base::TimeTicks::Now(); |
504 | 504 |
505 if (visual_depth_ < 24) { | 505 if (visual_depth_ < 24) { |
506 // CopyFromBackingStore() copies pixels out of the XImage | 506 // CopyFromBackingStore() copies pixels out of the XImage |
507 // in a way that assumes that each component (red, green, | 507 // in a way that assumes that each component (red, green, |
508 // blue) is a byte. This doesn't work on visuals which | 508 // blue) is a byte. This doesn't work on visuals which |
509 // encode a pixel color with less than a byte per color. | 509 // encode a pixel color with less than a byte per color. |
510 return false; | 510 return false; |
511 } | 511 } |
512 | 512 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 LOG(WARNING) << "Not using X shared memory."; | 564 LOG(WARNING) << "Not using X shared memory."; |
565 // Non-shared memory case just copy the image from the server. | 565 // Non-shared memory case just copy the image from the server. |
566 image = XGetImage(display_, pixmap_, | 566 image = XGetImage(display_, pixmap_, |
567 rect.x(), rect.y(), width, height, | 567 rect.x(), rect.y(), width, height, |
568 AllPlanes, ZPixmap); | 568 AllPlanes, ZPixmap); |
569 } | 569 } |
570 | 570 |
571 // TODO(jhawkins): Need to convert the image data if the image bits per pixel | 571 // TODO(jhawkins): Need to convert the image data if the image bits per pixel |
572 // is not 32. | 572 // is not 32. |
573 // Note that this also initializes the output bitmap as opaque. | 573 // Note that this also initializes the output bitmap as opaque. |
574 if (!output->initialize(width, height, true) || | 574 if (!output->Allocate(width, height, true) || |
575 image->bits_per_pixel != 32) { | 575 image->bits_per_pixel != 32) { |
576 if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) | 576 if (shared_memory_support_ != ui::SHARED_MEMORY_NONE) |
577 DestroySharedImage(display_, image, &shminfo); | 577 DestroySharedImage(display_, image, &shminfo); |
578 else | 578 else |
579 XDestroyImage(image); | 579 XDestroyImage(image); |
580 return false; | 580 return false; |
581 } | 581 } |
582 | 582 |
583 // The X image might have a different row stride, so iterate through | 583 // The X image might have a different row stride, so iterate through |
584 // it and copy each row out, only up to the pixels we're actually | 584 // it and copy each row out, only up to the pixels we're actually |
585 // using. This code assumes a visual mode where a pixel is | 585 // using. This code assumes a visual mode where a pixel is |
586 // represented using a 32-bit unsigned int, with a byte per component. | 586 // represented using a 32-bit unsigned int, with a byte per component. |
587 SkBitmap bitmap = skia::GetTopDevice(*output)->accessBitmap(true); | 587 const SkBitmap& bitmap = output->GetBitmap(); |
588 SkAutoLockPixels alp(bitmap); | 588 SkAutoLockPixels alp(bitmap); |
589 | 589 |
590 for (int y = 0; y < height; y++) { | 590 for (int y = 0; y < height; y++) { |
591 const uint32* src_row = reinterpret_cast<uint32*>( | 591 const uint32* src_row = reinterpret_cast<uint32*>( |
592 &image->data[image->bytes_per_line * y]); | 592 &image->data[image->bytes_per_line * y]); |
593 uint32* dest_row = bitmap.getAddr32(0, y); | 593 uint32* dest_row = bitmap.getAddr32(0, y); |
594 for (int x = 0; x < width; ++x, ++dest_row) { | 594 for (int x = 0; x < width; ++x, ++dest_row) { |
595 // Force alpha to be 0xff, because otherwise it causes rendering problems. | 595 // Force alpha to be 0xff, because otherwise it causes rendering problems. |
596 *dest_row = src_row[x] | 0xff000000; | 596 *dest_row = src_row[x] | 0xff000000; |
597 } | 597 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 | 681 |
682 cairo_identity_matrix(cr); | 682 cairo_identity_matrix(cr); |
683 | 683 |
684 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); | 684 cairo_rectangle(cr, rect.x(), rect.y(), rect.width(), rect.height()); |
685 cairo_fill(cr); | 685 cairo_fill(cr); |
686 cairo_destroy(cr); | 686 cairo_destroy(cr); |
687 } | 687 } |
688 #endif | 688 #endif |
689 | 689 |
690 } // namespace content | 690 } // namespace content |
OLD | NEW |