2014-11-25 03:11:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL EXPERIMENTAL
|
|
|
|
// DO NOT USE -- FOR INTERNAL TESTING ONLY
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/c/sk_canvas.h"
|
|
|
|
#include "include/c/sk_data.h"
|
|
|
|
#include "include/c/sk_image.h"
|
|
|
|
#include "include/c/sk_imageinfo.h"
|
|
|
|
#include "include/c/sk_paint.h"
|
|
|
|
#include "include/c/sk_shader.h"
|
|
|
|
#include "include/c/sk_surface.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/c/sk_types.h"
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2014-11-25 03:11:48 +00:00
|
|
|
|
|
|
|
extern void sk_test_c_api(sk_canvas_t*);
|
|
|
|
|
|
|
|
#define W 256
|
|
|
|
#define H 256
|
|
|
|
|
|
|
|
static sk_shader_t* make_shader() {
|
|
|
|
sk_point_t pts[] = { { 0, 0 }, { W, H } };
|
|
|
|
sk_color_t colors[] = { 0xFF00FF00, 0xFF0000FF };
|
|
|
|
return sk_shader_new_linear_gradient(pts, colors, NULL, 2, CLAMP_SK_SHADER_TILEMODE, NULL);
|
|
|
|
}
|
|
|
|
|
2014-12-25 22:16:21 +00:00
|
|
|
static void do_draw(sk_canvas_t* canvas) {
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_paint_t* paint = sk_paint_new();
|
|
|
|
sk_paint_set_antialias(paint, true);
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_paint_set_color(paint, 0xFFFFFFFF);
|
|
|
|
sk_canvas_draw_paint(canvas, paint);
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_rect_t r = { 10, 10, W - 10, H - 10 };
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_paint_set_color(paint, 0xFFFF0000);
|
|
|
|
sk_canvas_draw_rect(canvas, &r, paint);
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_shader_t* shader = make_shader();
|
|
|
|
sk_paint_set_shader(paint, shader);
|
|
|
|
sk_shader_unref(shader);
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_canvas_draw_oval(canvas, &r, paint);
|
2017-10-09 19:45:33 +00:00
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
sk_paint_delete(paint);
|
|
|
|
}
|
|
|
|
|
2014-12-25 22:16:21 +00:00
|
|
|
void sk_test_c_api(sk_canvas_t* canvas) {
|
|
|
|
do_draw(canvas);
|
|
|
|
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_imageinfo_t* info = sk_imageinfo_new(W, H, RGBA_8888_SK_COLORTYPE, OPAQUE_SK_ALPHATYPE,
|
|
|
|
NULL);
|
2015-06-23 13:26:08 +00:00
|
|
|
sk_surfaceprops_t surfaceProps = { UNKNOWN_SK_PIXELGEOMETRY };
|
2018-09-28 15:27:57 +00:00
|
|
|
sk_surface_t* surf = sk_surface_new_raster(info, &surfaceProps);
|
|
|
|
sk_imageinfo_delete(info);
|
2014-12-25 22:16:21 +00:00
|
|
|
do_draw(sk_surface_get_canvas(surf));
|
|
|
|
|
|
|
|
sk_image_t* img0 = sk_surface_new_image_snapshot(surf);
|
|
|
|
sk_surface_unref(surf);
|
|
|
|
|
|
|
|
sk_canvas_draw_image(canvas, img0, W + 10, 10, NULL);
|
|
|
|
|
|
|
|
sk_data_t* data = sk_image_encode(img0);
|
|
|
|
sk_image_unref(img0);
|
|
|
|
|
2020-07-28 16:52:31 +00:00
|
|
|
sk_image_t* img1 = sk_image_new_from_encoded(data);
|
2014-12-25 22:16:21 +00:00
|
|
|
sk_data_unref(data);
|
|
|
|
|
2014-12-26 04:41:13 +00:00
|
|
|
if (img1) {
|
|
|
|
sk_canvas_draw_image(canvas, img1, W/2, H/2, NULL);
|
|
|
|
sk_image_unref(img1);
|
|
|
|
}
|
2014-12-25 22:16:21 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 03:11:48 +00:00
|
|
|
|