blob: f85a442e9a46e4b00ef0a06c2a5988c4798dfeb7 [file] [log] [blame]
caryclark@google.com90adecd2012-10-16 12:31:48 +00001
2extern "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
18bool DrawPixman(SkCanvas* canvas, int step, bool useOld);
19SkCanvas* canvas;
20
21extern "C" {
22
23void*
24pixbuf_from_argb32 (uint32_t *bits,
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000025 int width,
26 int height,
27 int stride)
caryclark@google.com90adecd2012-10-16 12:31:48 +000028{
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 {
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000039 uint32_t *src_row = &bits[i * (stride / 4)];
40 uint32_t *dst_row = p_bits + i * (p_stride / 4);
caryclark@google.com90adecd2012-10-16 12:31:48 +000041
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000042 a8r8g8b8_to_rgba_np (dst_row, src_row, width);
caryclark@google.com90adecd2012-10-16 12:31:48 +000043 }
44 return (void*) bitmap;
45}
46
47
48void show_image (pixman_image_t *image) {
49 int width, height;
50 pixman_format_code_t format;
51 pixman_image_t *copy;
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000052
caryclark@google.com90adecd2012-10-16 12:31:48 +000053 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:
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000075 copy = pixman_image_ref (image);
76 break;
caryclark@google.com90adecd2012-10-16 12:31:48 +000077
78 default:
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000079 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;
caryclark@google.com90adecd2012-10-16 12:31:48 +000086 }
87
88 SkBitmap* bitmap = (SkBitmap*) pixbuf_from_argb32 (pixman_image_get_data (copy),
skia.committer@gmail.com20c301b2012-10-17 02:01:13 +000089 width, height,
90 pixman_image_get_stride (copy));
caryclark@google.com90adecd2012-10-16 12:31:48 +000091 canvas->drawBitmap(*bitmap, 0, 0);
92 delete bitmap;
93}
94
95}
96
97bool 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}