weston-ivi-shell: Move screenshot function from IVI-Shell to ivi-controller.
authorNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Wed, 25 Jun 2014 08:55:08 +0000 (17:55 +0900)
committerNobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
Thu, 21 Aug 2014 01:08:13 +0000 (10:08 +0900)
This is because ivi-shell shall not have dependency on other components
as much as possible. Now it depends on CAIRO.

Signed-off-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@denso.co.jp>
weston-ivi-shell/src/ivi-controller.c
weston-ivi-shell/src/ivi-layout-export.h

index 40c01f7..3b039f7 100755 (executable)
@@ -777,9 +777,9 @@ controller_surface_screenshot(struct wl_client *client,
                   struct wl_resource *resource,
                   const char *filename)
 {
-    struct ivisurface *ivisurf = wl_resource_get_user_data(resource);
     (void)client;
-    ivi_layout_takeSurfaceScreenshot(filename, ivisurf->layout_surface);
+    (void)resource;
+    (void)filename;
 }
 
 static void
@@ -1066,7 +1066,65 @@ controller_screen_screenshot(struct wl_client *client,
 {
     struct iviscreen *iviscrn = wl_resource_get_user_data(resource);
     (void)client;
-    ivi_layout_takeScreenshot(iviscrn->layout_screen, filename);
+
+    struct weston_output *output = NULL;
+    cairo_surface_t *cairo_surf = NULL;
+    int32_t i = 0;
+    int32_t width = 0;
+    int32_t height = 0;
+    int32_t stride = 0;
+    uint8_t *readpixs = NULL;
+    uint8_t *writepixs = NULL;
+    uint8_t *d = NULL;
+    uint8_t *s = NULL;
+
+    output = ivi_layout_screenGetOutput(iviscrn->layout_screen);
+    --output->disable_planes;
+
+    width = output->current_mode->width;
+    height = output->current_mode->height;
+    stride = width * (PIXMAN_FORMAT_BPP(output->compositor->read_format) / 8);
+
+    readpixs = malloc(stride * height);
+    if (readpixs == NULL) {
+        weston_log("fails to allocate memory\n");
+        return;
+    }
+
+    writepixs = malloc(stride * height);
+    if (writepixs == NULL) {
+        weston_log("fails to allocate memory\n");
+        return;
+    }
+
+    output->compositor->renderer->read_pixels(
+            output,
+            output->compositor->read_format,
+            readpixs,
+            0,
+            0,
+            width,
+            height);
+
+    s = readpixs;
+    d = writepixs + stride * (height - 1);
+
+    for (i = 0; i < height; ++i) {
+        memcpy(d, s, stride);
+        d -= stride;
+        s += stride;
+    }
+
+    cairo_surf = cairo_image_surface_create_for_data(
+            writepixs,
+            CAIRO_FORMAT_ARGB32,
+            width,
+            height,
+            stride);
+    cairo_surface_write_to_png(cairo_surf, filename);
+    cairo_surface_destroy(cairo_surf);
+    free(writepixs);
+    free(readpixs);
 }
 
 static void
index 9784cf3..25deeb8 100644 (file)
@@ -833,39 +833,6 @@ ivi_layout_screenSetRenderOrder(struct ivi_layout_screen *iviscrn,
                                    const uint32_t number);
 
 /**
- * \brief Take a screenshot from the current displayed layer scene.
- * The screenshot is saved as bmp file with the corresponding filename.
- *
- * \return  0 if the method call was successful
- * \return -1 if the method call was failed
- */
-int32_t
-ivi_layout_takeScreenshot(struct ivi_layout_screen *iviscrn,
-                             const char *filename);
-
-/**
- * \brief Take a screenshot of a certain layer
- * The screenshot is saved as bmp file with the corresponding filename.
- *
- * \return  0 if the method call was successful
- * \return -1 if the method call was failed
- */
-int32_t
-ivi_layout_takeLayerScreenshot(const char *filename,
-                                  struct ivi_layout_layer *ivilayer);
-
-/**
- * \brief Take a screenshot of a certain surface
- * The screenshot is saved as bmp file with the corresponding filename.
- *
- * \return  0 if the method call was successful
- * \return -1 if the method call was failed
- */
-int32_t
-ivi_layout_takeSurfaceScreenshot(const char *filename,
-                                    struct ivi_layout_surface *ivisurf);
-
-/**
  * \brief Enable or disable a rendering optimization
  *
  * \return  0 if the method call was successful
@@ -945,6 +912,16 @@ ivi_layout_surfaceSetSourceRectangle(struct ivi_layout_surface *ivisurf,
                                         uint32_t width, uint32_t height);
 
 /**
+ * \brief get weston_output from ivi_layout_screen.
+ *
+ * \return (struct weston_screen *)
+ *              if the method call was successful
+ * \return NULL if the method call was failed
+ */
+struct weston_output *
+ivi_layout_screenGetOutput(struct ivi_layout_screen *);
+
+/**
  * \brief Commit all changes and execute all enqueued commands since last commit.
  *
  * \return  0 if the method call was successful