Home | History | Annotate | Download | only in pixman
      1 
      2 extern "C" {
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <config.h>
      6 #include "pixman-private.h"
      7 #include "utils.h"
      8 #include "gtk-utils.h"
      9 
     10 }
     11 
     12 #include "SkBitmap.h"
     13 #include "SkCanvas.h"
     14 #include "SkGraphics.h"
     15 #include "SkPaint.h"
     16 #import "SkWindow.h"
     17 
     18 bool DrawPixman(SkCanvas* canvas, int step, bool useOld);
     19 SkCanvas* canvas;
     20 
     21 extern "C" {
     22 
     23 void*
     24 pixbuf_from_argb32 (uint32_t *bits,
     25             int width,
     26             int height,
     27             int stride)
     28 {
     29     SkBitmap* bitmap = new SkBitmap;
     30     bitmap->setConfig(SkBitmap::kARGB_8888_Config, width, height);
     31     bitmap->allocPixels();
     32 
     33     int p_stride = bitmap->rowBytes();
     34     uint32_t *p_bits = bitmap->getAddr32(0, 0);
     35     int i;
     36 
     37     for (i = 0; i < height; ++i)
     38     {
     39     uint32_t *src_row = &bits[i * (stride / 4)];
     40     uint32_t *dst_row = p_bits + i * (p_stride / 4);
     41 
     42     a8r8g8b8_to_rgba_np (dst_row, src_row, width);
     43     }
     44     return (void*) bitmap;
     45 }
     46 
     47 
     48 void show_image (pixman_image_t *image) {
     49     int width, height;
     50     pixman_format_code_t format;
     51     pixman_image_t *copy;
     52 
     53     width = pixman_image_get_width (image);
     54     height = pixman_image_get_height (image);
     55 
     56 
     57     format = pixman_image_get_format (image);
     58 
     59     /* Three cases:
     60      *
     61      *  - image is a8r8g8b8_sRGB: we will display without modification
     62      *    under the assumption that the monitor is sRGB
     63      *
     64      *  - image is a8r8g8b8: we will display without modification
     65      *    under the assumption that whoever created the image
     66      *    probably did it wrong by using sRGB inputs
     67      *
     68      *  - other: we will convert to a8r8g8b8 under the assumption that
     69      *    whoever created the image probably did it wrong.
     70      */
     71     switch (format)
     72     {
     73     case PIXMAN_a8r8g8b8_sRGB:
     74     case PIXMAN_a8r8g8b8:
     75     copy = pixman_image_ref (image);
     76     break;
     77 
     78     default:
     79     copy = pixman_image_create_bits (PIXMAN_a8r8g8b8,
     80                      width, height, NULL, -1);
     81     pixman_image_composite32 (PIXMAN_OP_SRC,
     82                   image, NULL, copy,
     83                   0, 0, 0, 0, 0, 0,
     84                   width, height);
     85     break;
     86     }
     87 
     88     SkBitmap* bitmap = (SkBitmap*) pixbuf_from_argb32 (pixman_image_get_data (copy),
     89                  width, height,
     90                  pixman_image_get_stride (copy));
     91     canvas->drawBitmap(*bitmap, 0, 0);
     92     delete bitmap;
     93 }
     94 
     95 }
     96 
     97 bool DrawPixman(SkCanvas* c, int step, bool usePixman) {
     98     canvas = c;
     99     switch(step) {
    100         case 0:
    101             checkerboard_main(0, NULL);
    102             break;
    103         default:
    104             alpha_main(0, NULL);
    105             break;
    106     }
    107     return true;
    108 }
    109