diff options
| author | Bryce Harrington <b.harrington@samsung.com> | 2014-05-31 07:14:21 +0900 |
|---|---|---|
| committer | Bryce Harrington <b.harrington@samsung.com> | 2014-05-31 07:14:21 +0900 |
| commit | 8a5ac0ac095d09564aecb340d4bf58bbecfe63c9 (patch) | |
| tree | d9656fef9e2806858dfa31f7b50e96c392267b87 /src | |
| parent | 636f6a31c35d6d1825eabc92b91cedb6c12b4906 (diff) | |
| parent | 11ce9a1775b62ce2d199a4ab0f4f82b92603b483 (diff) | |
Merge pull request #67 from Samsung/Issue_65
Create window for image backend.
ref: https://github.com/Samsung/caskbench/issues/65
Diffstat (limited to 'src')
| -rw-r--r-- | src/cairo-image.cpp | 38 | ||||
| -rw-r--r-- | src/image.cpp | 53 | ||||
| -rw-r--r-- | src/image.h | 9 | ||||
| -rw-r--r-- | src/skia-image.cpp | 38 |
4 files changed, 126 insertions, 12 deletions
diff --git a/src/cairo-image.cpp b/src/cairo-image.cpp index 5db97fe..1d6d918 100644 --- a/src/cairo-image.cpp +++ b/src/cairo-image.cpp @@ -12,28 +12,42 @@ #include "forward.h" #include "image.h" -#include "device_config.h" static image_state_t *state; +cairo_surface_t *cairo_surface; + +static int +convert_cairo_surface_to_ximage (cairo_surface_t *surface) +{ + unsigned char *data = cairo_image_surface_get_data (surface); + state->image.width = cairo_image_surface_get_width (surface); + state->image.height = cairo_image_surface_get_height (surface); + state->image.format = ZPixmap; + state->image.data = (char*)data; + state->image.bitmap_unit = 4 * 8; + state->image.byte_order = LSBFirst; + state->image.bitmap_bit_order = LSBFirst; + state->image.bitmap_pad = 4 * 8; + state->image.depth = 32; + state->image.bytes_per_line = state->image.width * 4; + state->image.bits_per_pixel = 4 * 8; + Status status = XInitImage (&state->image); + return status; +} cairo_surface_t * create_cairo_surface_image (const device_config_t& config) { - cairo_surface_t *cairo_surface; - state = (image_state_t*) malloc (sizeof (image_state_t)); if (!state) { warnx ("Out of memory\n"); return NULL; } - /* - state->dpy = XOpenDisplay (NULL); - if (state->dpy == NULL) { - warnx ("Failed to open display: %s\n", XDisplayName (0)); - return NULL; - } - */ + if (!createImageWindow(state, config)) { + cleanup_state_image(state); + return NULL; + } cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, config.width, @@ -45,12 +59,16 @@ create_cairo_surface_image (const device_config_t& config) void destroy_cairo_image(void) { + destroyImageWindow(state); cleanup_state_image(state); } void update_cairo_image(void) { + if (convert_cairo_surface_to_ximage (cairo_surface)) { + updateImageWindow(state); + } } /* diff --git a/src/image.cpp b/src/image.cpp index b17b612..4462ecc 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -9,6 +9,7 @@ #include <err.h> #include <stdlib.h> +#include "device_config.h" #include "image.h" void @@ -18,6 +19,58 @@ cleanup_state_image (void *data) free(state); } +bool +createImageWindow(image_state_t *state, const device_config_t& device_config) +{ + state->dpy = XOpenDisplay (NULL); + if (!state->dpy) { + warnx ("fail to open display: %s\n", XDisplayName (0)); + return false; + } + + int screen = DefaultScreen (state->dpy); + + XVisualInfo vi; + XSetWindowAttributes attrs; + + XMatchVisualInfo (state->dpy, screen, 32, TrueColor, &vi); + attrs.border_pixel = 0; + attrs.event_mask = StructureNotifyMask; + attrs.colormap = XCreateColormap (state->dpy, DefaultRootWindow (state->dpy), + vi.visual, AllocNone); + state->window = XCreateWindow (state->dpy, DefaultRootWindow (state->dpy), + 0, 0, + device_config.width, device_config.height, + 0, + vi.depth, + InputOutput, vi.visual, + CWBorderPixel | CWColormap | CWEventMask, + &attrs); + state->width = device_config.width; + state->height = device_config.height; + XMapWindow (state->dpy, state->window); + + state->gc = XCreateGC (state->dpy, state->window, 0, NULL); + return true; +} + +void +updateImageWindow(image_state_t* state) +{ + XPutImage (state->dpy, state->window, state->gc, &state->image, + 0, 0, + 0, 0, + state->width, state->height); + XSync (state->dpy, False); +} +void +destroyImageWindow(image_state_t* state) +{ + XFreeGC (state->dpy, state->gc); + XDestroyWindow (state->dpy, state->window); + XCloseDisplay (state->dpy); +} + /* Local Variables: mode:c++ diff --git a/src/image.h b/src/image.h index 1ff1485..a2f8601 100644 --- a/src/image.h +++ b/src/image.h @@ -8,13 +8,22 @@ #define __EGL_H__ #include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <device_config.h> typedef struct { Display *dpy; Window window; + GC gc; + XImage image; + int width; + int height; } image_state_t; void cleanup_state_image(void *data); +bool createImageWindow(image_state_t *state, const device_config_t& device_config); +void destroyImageWindow(image_state_t *state); +void updateImageWindow(image_state_t *state); #endif // __EGL_H__ /* diff --git a/src/skia-image.cpp b/src/skia-image.cpp index bb20612..67864bf 100644 --- a/src/skia-image.cpp +++ b/src/skia-image.cpp @@ -12,14 +12,38 @@ #include <SkBitmapDevice.h> #include "image.h" -#include "device_config.h" static image_state_t *state; +SkBitmap skia_bitmap; + +static bool convertBitmapToXImage(const SkBitmap& bitmap) { + sk_bzero(&state->image, sizeof(state->image)); + + int bitsPerPixel = bitmap.bytesPerPixel() * 8; + state->image.width = bitmap.width(); + state->image.height = bitmap.height(); + state->image.format = ZPixmap; + state->image.data = (char*) bitmap.getPixels(); + state->image.byte_order = LSBFirst; + state->image.bitmap_unit = 4 * 8; + state->image.bitmap_bit_order = LSBFirst; + state->image.bitmap_pad = 4 * 8; + state->image.depth = 32; + state->image.bytes_per_line = bitmap.width() * 4; + state->image.bits_per_pixel = 4 * 8; + return XInitImage(&state->image); +} + SkBaseDevice * create_skia_device_image (const device_config_t& config) { - SkBitmap skia_bitmap; + state = (image_state_t*) malloc (sizeof (image_state_t)); + if (!state) { + warnx ("Out of memory\n"); + return NULL; + } + if (!skia_bitmap.setConfig(SkBitmap::kARGB_8888_Config, config.width, config.height)) { warnx("Failed to configure bitmap\n"); @@ -32,18 +56,28 @@ create_skia_device_image (const device_config_t& config) warnx("Failed to allocate pixels\n"); return NULL; } + + if (!createImageWindow(state, config)) { + cleanup_state_image(state); + return NULL; + } + return new SkBitmapDevice (skia_bitmap); } void destroy_skia_image(void) { + destroyImageWindow(state); cleanup_state_image(state); } void update_skia_image(void) { + if (convertBitmapToXImage (skia_bitmap)) { + updateImageWindow(state); + } } /* |