Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: ui/base/x/x11_util.cc

Issue 8772021: Enable GL_CHROMIUM_post_sub_buffer for osmesa (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: "" Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/gfx/gl/gl_surface_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "ui/base/x/x11_util.h" 9 #include "ui/base/x/x11_util.h"
10 10
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 NOTREACHED(); 577 NOTREACHED();
578 } 578 }
579 579
580 XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap) { 580 XID CreatePictureFromSkiaPixmap(Display* display, XID pixmap) {
581 XID picture = XRenderCreatePicture( 581 XID picture = XRenderCreatePicture(
582 display, pixmap, GetRenderARGB32Format(display), 0, NULL); 582 display, pixmap, GetRenderARGB32Format(display), 0, NULL);
583 583
584 return picture; 584 return picture;
585 } 585 }
586 586
587 void PutARGBImage(Display* display, void* visual, int depth, XID pixmap, 587 void PutARGBImage(Display* display,
588 void* pixmap_gc, const uint8* data, int width, int height) { 588 void* visual, int depth,
589 XID pixmap, void* pixmap_gc,
590 const uint8* data,
591 int width, int height) {
592 PutARGBImage(display,
593 visual, depth,
594 pixmap, pixmap_gc,
595 data, width, height,
596 0, 0, // src_x, src_y
597 0, 0, // dst_x, dst_y
598 width, height);
599 }
600
601 void PutARGBImage(Display* display,
602 void* visual, int depth,
603 XID pixmap, void* pixmap_gc,
604 const uint8* data,
605 int data_width, int data_height,
606 int src_x, int src_y,
607 int dst_x, int dst_y,
608 int copy_width, int copy_height) {
589 // TODO(scherkus): potential performance impact... consider passing in as a 609 // TODO(scherkus): potential performance impact... consider passing in as a
590 // parameter. 610 // parameter.
591 int pixmap_bpp = BitsPerPixelForPixmapDepth(display, depth); 611 int pixmap_bpp = BitsPerPixelForPixmapDepth(display, depth);
592 612
593 XImage image; 613 XImage image;
594 memset(&image, 0, sizeof(image)); 614 memset(&image, 0, sizeof(image));
595 615
596 image.width = width; 616 image.width = data_width;
597 image.height = height; 617 image.height = data_height;
598 image.format = ZPixmap; 618 image.format = ZPixmap;
599 image.byte_order = LSBFirst; 619 image.byte_order = LSBFirst;
600 image.bitmap_unit = 8; 620 image.bitmap_unit = 8;
601 image.bitmap_bit_order = LSBFirst; 621 image.bitmap_bit_order = LSBFirst;
602 image.depth = depth; 622 image.depth = depth;
603 image.bits_per_pixel = pixmap_bpp; 623 image.bits_per_pixel = pixmap_bpp;
604 image.bytes_per_line = width * pixmap_bpp / 8; 624 image.bytes_per_line = data_width * pixmap_bpp / 8;
605 625
606 if (pixmap_bpp == 32) { 626 if (pixmap_bpp == 32) {
607 image.red_mask = 0xff0000; 627 image.red_mask = 0xff0000;
608 image.green_mask = 0xff00; 628 image.green_mask = 0xff00;
609 image.blue_mask = 0xff; 629 image.blue_mask = 0xff;
610 630
611 // If the X server depth is already 32-bits and the color masks match, 631 // If the X server depth is already 32-bits and the color masks match,
612 // then our job is easy. 632 // then our job is easy.
613 Visual* vis = static_cast<Visual*>(visual); 633 Visual* vis = static_cast<Visual*>(visual);
614 if (image.red_mask == vis->red_mask && 634 if (image.red_mask == vis->red_mask &&
615 image.green_mask == vis->green_mask && 635 image.green_mask == vis->green_mask &&
616 image.blue_mask == vis->blue_mask) { 636 image.blue_mask == vis->blue_mask) {
617 image.data = const_cast<char*>(reinterpret_cast<const char*>(data)); 637 image.data = const_cast<char*>(reinterpret_cast<const char*>(data));
618 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image, 638 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image,
619 0, 0 /* source x, y */, 0, 0 /* dest x, y */, 639 src_x, src_y, dst_x, dst_y,
620 width, height); 640 copy_width, copy_height);
621 } else { 641 } else {
622 // Otherwise, we need to shuffle the colors around. Assume red and blue 642 // Otherwise, we need to shuffle the colors around. Assume red and blue
623 // need to be swapped. 643 // need to be swapped.
624 // 644 //
625 // It's possible to use some fancy SSE tricks here, but since this is the 645 // It's possible to use some fancy SSE tricks here, but since this is the
626 // slow path anyway, we do it slowly. 646 // slow path anyway, we do it slowly.
627 647
628 uint8_t* bitmap32 = static_cast<uint8_t*>(malloc(4 * width * height)); 648 uint8_t* bitmap32 =
649 static_cast<uint8_t*>(malloc(4 * data_width * data_height));
629 if (!bitmap32) 650 if (!bitmap32)
630 return; 651 return;
631 uint8_t* const orig_bitmap32 = bitmap32; 652 uint8_t* const orig_bitmap32 = bitmap32;
632 const uint32_t* bitmap_in = reinterpret_cast<const uint32_t*>(data); 653 const uint32_t* bitmap_in = reinterpret_cast<const uint32_t*>(data);
633 for (int y = 0; y < height; ++y) { 654 for (int y = 0; y < data_height; ++y) {
634 for (int x = 0; x < width; ++x) { 655 for (int x = 0; x < data_width; ++x) {
635 const uint32_t pixel = *(bitmap_in++); 656 const uint32_t pixel = *(bitmap_in++);
636 bitmap32[0] = (pixel >> 16) & 0xff; // Red 657 bitmap32[0] = (pixel >> 16) & 0xff; // Red
637 bitmap32[1] = (pixel >> 8) & 0xff; // Green 658 bitmap32[1] = (pixel >> 8) & 0xff; // Green
638 bitmap32[2] = pixel & 0xff; // Blue 659 bitmap32[2] = pixel & 0xff; // Blue
639 bitmap32[3] = (pixel >> 24) & 0xff; // Alpha 660 bitmap32[3] = (pixel >> 24) & 0xff; // Alpha
640 bitmap32 += 4; 661 bitmap32 += 4;
641 } 662 }
642 } 663 }
643 image.data = reinterpret_cast<char*>(orig_bitmap32); 664 image.data = reinterpret_cast<char*>(orig_bitmap32);
644 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image, 665 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image,
645 0, 0 /* source x, y */, 0, 0 /* dest x, y */, 666 src_x, src_y, dst_x, dst_y,
646 width, height); 667 copy_width, copy_height);
647 free(orig_bitmap32); 668 free(orig_bitmap32);
648 } 669 }
649 } else if (pixmap_bpp == 16) { 670 } else if (pixmap_bpp == 16) {
650 // Some folks have VNC setups which still use 16-bit visuals and VNC 671 // Some folks have VNC setups which still use 16-bit visuals and VNC
651 // doesn't include Xrender. 672 // doesn't include Xrender.
652 673
653 uint16_t* bitmap16 = static_cast<uint16_t*>(malloc(2 * width * height)); 674 uint16_t* bitmap16 =
675 static_cast<uint16_t*>(malloc(2 * data_width * data_height));
654 if (!bitmap16) 676 if (!bitmap16)
655 return; 677 return;
656 uint16_t* const orig_bitmap16 = bitmap16; 678 uint16_t* const orig_bitmap16 = bitmap16;
657 const uint32_t* bitmap_in = reinterpret_cast<const uint32_t*>(data); 679 const uint32_t* bitmap_in = reinterpret_cast<const uint32_t*>(data);
658 for (int y = 0; y < height; ++y) { 680 for (int y = 0; y < data_height; ++y) {
659 for (int x = 0; x < width; ++x) { 681 for (int x = 0; x < data_width; ++x) {
660 const uint32_t pixel = *(bitmap_in++); 682 const uint32_t pixel = *(bitmap_in++);
661 uint16_t out_pixel = ((pixel >> 8) & 0xf800) | 683 uint16_t out_pixel = ((pixel >> 8) & 0xf800) |
662 ((pixel >> 5) & 0x07e0) | 684 ((pixel >> 5) & 0x07e0) |
663 ((pixel >> 3) & 0x001f); 685 ((pixel >> 3) & 0x001f);
664 *(bitmap16++) = out_pixel; 686 *(bitmap16++) = out_pixel;
665 } 687 }
666 } 688 }
667 689
668 image.data = reinterpret_cast<char*>(orig_bitmap16); 690 image.data = reinterpret_cast<char*>(orig_bitmap16);
669 image.red_mask = 0xf800; 691 image.red_mask = 0xf800;
670 image.green_mask = 0x07e0; 692 image.green_mask = 0x07e0;
671 image.blue_mask = 0x001f; 693 image.blue_mask = 0x001f;
672 694
673 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image, 695 XPutImage(display, pixmap, static_cast<GC>(pixmap_gc), &image,
674 0, 0 /* source x, y */, 0, 0 /* dest x, y */, 696 src_x, src_y, dst_x, dst_y,
675 width, height); 697 copy_width, copy_height);
676 free(orig_bitmap16); 698 free(orig_bitmap16);
677 } else { 699 } else {
678 LOG(FATAL) << "Sorry, we don't support your visual depth without " 700 LOG(FATAL) << "Sorry, we don't support your visual depth without "
679 "Xrender support (depth:" << depth 701 "Xrender support (depth:" << depth
680 << " bpp:" << pixmap_bpp << ")"; 702 << " bpp:" << pixmap_bpp << ")";
681 } 703 }
682 } 704 }
683 705
684 void FreePicture(Display* display, XID picture) { 706 void FreePicture(Display* display, XID picture) {
685 XRenderFreePicture(display, picture); 707 XRenderFreePicture(display, picture);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 << "request_code " << static_cast<int>(error_event.request_code) << ", " 956 << "request_code " << static_cast<int>(error_event.request_code) << ", "
935 << "minor_code " << static_cast<int>(error_event.minor_code) 957 << "minor_code " << static_cast<int>(error_event.minor_code)
936 << " (" << request_str << ")"; 958 << " (" << request_str << ")";
937 } 959 }
938 960
939 // ---------------------------------------------------------------------------- 961 // ----------------------------------------------------------------------------
940 // End of x11_util_internal.h 962 // End of x11_util_internal.h
941 963
942 964
943 } // namespace ui 965 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | ui/gfx/gl/gl_surface_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698