├── .gitignore ├── AUTHORS ├── CMakeLists.txt ├── CMakeScripts ├── Modules │ ├── FindCairo.cmake │ ├── FindOpenGLES2.cmake │ ├── FindOpenGLES3.cmake │ ├── FindPopt.cmake │ └── FindSkia.cmake └── cmake_uninstall.cmake.in ├── COPYING ├── ChangeLog ├── DESIGN ├── HACKING ├── KNOWN_ISSUES ├── NEWS ├── README ├── TODO ├── config.h.cmake ├── index.html ├── packaging ├── caskbench.manifest └── caskbench.spec ├── src ├── CMakeLists.txt ├── cairo-egl.cpp ├── cairo-glx.cpp ├── cairo-image.cpp ├── cairo-shapes.cpp ├── cairo-shapes.h ├── cairo-tests │ ├── animation.cpp │ ├── bubbles.cpp │ ├── circle.cpp │ ├── clip.cpp │ ├── cubic.cpp │ ├── curves.cpp │ ├── fill.cpp │ ├── hline.cpp │ ├── image-rotate.cpp │ ├── image-scale.cpp │ ├── image.cpp │ ├── line.cpp │ ├── linear-gradient.cpp │ ├── mask.cpp │ ├── multi-line.cpp │ ├── multi-shape.cpp │ ├── paint.cpp │ ├── quadratic.cpp │ ├── radial-gradient.cpp │ ├── rect.cpp │ ├── rectangles.cpp │ ├── roundrect.cpp │ ├── shadow.cpp │ ├── star.cpp │ ├── stroke.cpp │ ├── text-glyphs.cpp │ ├── text.cpp │ ├── transform.cpp │ └── vline.cpp ├── cairo-util.cpp ├── caskbench.cpp ├── caskbench.h ├── caskbench_context.cpp ├── caskbench_context.h ├── caskbench_result.cpp ├── caskbench_result.h ├── device_config.h ├── egl.cpp ├── egl.h ├── forward.h ├── generate_git_info ├── generate_tests ├── git_info.h ├── glx.cpp ├── glx.h ├── image.cpp ├── image.h ├── kinetics.cpp ├── kinetics.h ├── rnd.cpp ├── rnd.h ├── shapes.cpp ├── shapes.h ├── skia-egl.cpp ├── skia-glx.cpp ├── skia-image.cpp ├── skia-shapes.cpp ├── skia-shapes.h ├── skia-tests │ ├── animation.cpp │ ├── bubbles.cpp │ ├── circle.cpp │ ├── clip.cpp │ ├── cubic.cpp │ ├── curves.cpp │ ├── fill.cpp │ ├── hline.cpp │ ├── image-rotate.cpp │ ├── image-scale.cpp │ ├── image.cpp │ ├── line.cpp │ ├── linear-gradient.cpp │ ├── mask.cpp │ ├── multi-line.cpp │ ├── multi-shape.cpp │ ├── paint.cpp │ ├── quadratic.cpp │ ├── radial-gradient.cpp │ ├── rect.cpp │ ├── roundrect.cpp │ ├── shadow.cpp │ ├── star.cpp │ ├── stroke.cpp │ ├── text-glyphs.cpp │ ├── text.cpp │ ├── transform.cpp │ └── vline.cpp ├── skia-util.cpp └── tests.h └── utils ├── compare_runs ├── flashcanvas ├── json2csv ├── make_index ├── mandel.png ├── run_benchmark └── system_description.sh /.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | 5 | # Libraries 6 | *.lib 7 | *.a 8 | 9 | # Shared objects (inc. Windows DLLs) 10 | *.dll 11 | *.so 12 | *.so.* 13 | *.dylib 14 | 15 | # Executables 16 | *.exe 17 | *.out 18 | *.app 19 | 20 | build* 21 | INSTALL 22 | Makefile 23 | *.pc 24 | *~ 25 | *.bak 26 | *.bin 27 | core 28 | *-ISO*.bdf 29 | *-JIS*.bdf 30 | *-KOI8*.bdf 31 | *.kld 32 | *.ko.cmd 33 | *.lai 34 | *.l[oa] 35 | *.obj 36 | *.patch 37 | *.pcf.gz 38 | *.pdb 39 | *.tar.bz2 40 | *.tar.gz 41 | 42 | # Test output 43 | cairo-*.png 44 | skia-*.png 45 | results-* 46 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Bryce Harrington 2 | Suyambulingam Rathinasamy Muthupandi 3 | Srikanth Chevalam 4 | -------------------------------------------------------------------------------- /CMakeScripts/Modules/FindCairo.cmake: -------------------------------------------------------------------------------- 1 | # Find the Cairo library 2 | # 3 | # This defines: 4 | # 5 | # CAIRO_FOUND 6 | # CAIRO_GL_FOUND 7 | # CAIRO_INCLUDE_DIRS 8 | # CAIRO_GL_INCLUDE_DIRS 9 | # CAIRO_LIBRARIES 10 | 11 | find_library(CAIRO_LIBRARIES 12 | NAMES cairo 13 | PATHS 14 | $ENV{CAIRO_DIR}/lib 15 | $ENV{CAIRO_DIR} 16 | /usr/local/lib 17 | /usr/lib 18 | /opt/lib 19 | ) 20 | find_path(CAIRO_INCLUDE_DIRS 21 | NAMES cairo.h 22 | PATH_SUFFIXES cairo 23 | PATHS 24 | $ENV{CAIRO_DIR}/include 25 | $ENV{CAIRO_DIR} 26 | /usr/local/include 27 | /usr/include 28 | /opt/include 29 | ) 30 | find_path(CAIRO_GL_INCLUDE_DIRS 31 | NAMES cairo-gl.h 32 | PATH_SUFFIXES cairo 33 | PATHS 34 | $ENV{CAIRO_DIR}/include 35 | $ENV{CAIRO_DIR} 36 | /usr/local/include 37 | /usr/include 38 | /opt/include 39 | ) 40 | 41 | set (CAIRO_FOUND "NO") 42 | if (CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) 43 | set (CAIRO_FOUND "YES") 44 | else (CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) 45 | if (Cairo_FIND_REQUIRED) 46 | message(FATAL_ERROR "Could not find Cairo") 47 | endif (Cairo_FIND_REQUIRED) 48 | endif (CAIRO_LIBRARIES AND CAIRO_INCLUDE_DIRS) 49 | 50 | set (CAIRO_GL_FOUND "NO") 51 | if (CAIRO_LIBRARIES AND CAIRO_GL_INCLUDE_DIRS) 52 | set (CAIRO_GL_FOUND "YES") 53 | endif (CAIRO_LIBRARIES AND CAIRO_GL_INCLUDE_DIRS) 54 | 55 | # TODO: Check for EGL support 56 | # - locate symbols cairo_egl_device_create and cairo_gl_surface_create_for_egl -------------------------------------------------------------------------------- /CMakeScripts/Modules/FindOpenGLES2.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file was derived from the CMake build system for OGRE 3 | # (http://www.ogre3d.org/) from the following link: 4 | # 5 | # http://gamekit.googlecode.com/svn/trunk/CMake/Packages/FindOpenGLES3.cmake 6 | # 7 | #------------------------------------------------------------------- 8 | # OGRE License: 9 | # 10 | # The contents of this file are placed in the public domain. Feel 11 | # free to make use of it in any way you like. 12 | #------------------------------------------------------------------- 13 | 14 | # - Try to find OpenGLES and EGL 15 | # Once done this will define 16 | # 17 | # OPENGLES2_FOUND - system has OpenGLES 18 | # OPENGLES2_INCLUDE_DIR - the GL include directory 19 | # OPENGLES2_LIBRARIES - Link these to use OpenGLES 20 | # 21 | # EGL_FOUND - system has EGL 22 | # EGL_INCLUDE_DIR - the EGL include directory 23 | # EGL_LIBRARIES - Link these to use EGL 24 | 25 | 26 | FIND_PATH(OPENGLES2_INCLUDE_DIR GLES2/gl2.h 27 | /usr/openwin/share/include 28 | /opt/graphics/OpenGL/include /usr/X11R6/include 29 | /usr/include 30 | ) 31 | 32 | FIND_LIBRARY(OPENGLES2_gl_LIBRARY 33 | NAMES GLESv2 34 | PATHS /opt/graphics/OpenGL/lib 35 | /usr/openwin/lib 36 | /usr/shlib /usr/X11R6/lib 37 | /usr/lib 38 | ) 39 | 40 | FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h 41 | /usr/openwin/share/include 42 | /opt/graphics/OpenGL/include /usr/X11R6/include 43 | /usr/include 44 | ) 45 | 46 | FIND_LIBRARY(EGL_egl_LIBRARY 47 | NAMES EGL 48 | PATHS /opt/graphics/OpenGL/lib 49 | /usr/openwin/lib 50 | /usr/shlib /usr/X11R6/lib 51 | /usr/lib 52 | ) 53 | 54 | # On Unix OpenGL most certainly always requires X11. 55 | # Feel free to tighten up these conditions if you don't 56 | # think this is always true. 57 | # It's not true on OSX. 58 | 59 | IF (OPENGLES2_gl_LIBRARY) 60 | IF(NOT X11_FOUND) 61 | INCLUDE(FindX11) 62 | ENDIF(NOT X11_FOUND) 63 | IF (X11_FOUND) 64 | SET (OPENGLES2_LIBRARIES ${X11_LIBRARIES}) 65 | ENDIF (X11_FOUND) 66 | ENDIF (OPENGLES2_gl_LIBRARY) 67 | 68 | SET( OPENGLES2_FOUND "YES" ) 69 | IF(OPENGLES2_gl_LIBRARY AND EGL_egl_LIBRARY) 70 | 71 | SET( OPENGLES2_LIBRARIES ${OPENGLES2_gl_LIBRARY} ${OPENGLES2_LIBRARIES}) 72 | SET( EGL_LIBRARIES ${EGL_egl_LIBRARY} ${EGL_LIBRARIES}) 73 | SET( OPENGLES2_FOUND "YES" ) 74 | 75 | ENDIF(OPENGLES2_gl_LIBRARY AND EGL_egl_LIBRARY) 76 | 77 | MARK_AS_ADVANCED( 78 | OPENGLES2_INCLUDE_DIR 79 | OPENGLES2_gl_LIBRARY 80 | EGL_INCLUDE_DIR 81 | EGL_egl_LIBRARY 82 | ) 83 | -------------------------------------------------------------------------------- /CMakeScripts/Modules/FindOpenGLES3.cmake: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------- 2 | # This file was taken from the CMake build system for OGRE 3 | # (http://www.ogre3d.org/) from the following link: 4 | # 5 | # http://gamekit.googlecode.com/svn/trunk/CMake/Packages/FindOpenGLES3.cmake 6 | # 7 | #------------------------------------------------------------------- 8 | # OGRE License: 9 | # 10 | # The contents of this file are placed in the public domain. Feel 11 | # free to make use of it in any way you like. 12 | #------------------------------------------------------------------- 13 | 14 | # - Try to find OpenGLES and EGL 15 | # Once done this will define 16 | # 17 | # OPENGLES3_FOUND - system has OpenGLES 18 | # OPENGLES3_INCLUDE_DIR - the GL include directory 19 | # OPENGLES3_LIBRARIES - Link these to use OpenGLES 20 | # 21 | # EGL_FOUND - system has EGL 22 | # EGL_INCLUDE_DIR - the EGL include directory 23 | # EGL_LIBRARIES - Link these to use EGL 24 | 25 | IF (WIN32) 26 | IF (CYGWIN) 27 | 28 | FIND_PATH(OPENGLES3_INCLUDE_DIR GLES3/gl3.h ) 29 | 30 | FIND_LIBRARY(OPENGLES3_gl_LIBRARY libGLESv2 ) 31 | 32 | ELSE (CYGWIN) 33 | 34 | IF(BORLAND) 35 | SET (OPENGLES3_gl_LIBRARY import32 CACHE STRING "OpenGL ES 3.x library for win32") 36 | ELSE(BORLAND) 37 | SET(POWERVR_SDK_PATH "C:/Imagination/PowerVR/GraphicsSDK/SDK_3.0/Builds/OGLES3") 38 | FIND_PATH(OPENGLES3_INCLUDE_DIR GLES3/gl3.h 39 | ${POWERVR_SDK_PATH}/Include 40 | ) 41 | 42 | FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h 43 | ${POWERVR_SDK_PATH}/Include 44 | ) 45 | 46 | FIND_LIBRARY(OPENGLES3_gl_LIBRARY 47 | NAMES libGLESv2 48 | PATHS ${POWERVR_SDK_PATH}/Windows_x86_32/Lib 49 | ) 50 | 51 | FIND_LIBRARY(EGL_egl_LIBRARY 52 | NAMES libEGL 53 | PATHS ${POWERVR_SDK_PATH}/Windows_x86_32/Lib 54 | ) 55 | ENDIF(BORLAND) 56 | 57 | ENDIF (CYGWIN) 58 | 59 | ELSE (WIN32) 60 | 61 | IF (APPLE) 62 | 63 | create_search_paths(/Developer/Platforms) 64 | findpkg_framework(OpenGLES3) 65 | set(OPENGLES3_gl_LIBRARY "-framework OpenGLES") 66 | 67 | ELSE(APPLE) 68 | 69 | FIND_PATH(OPENGLES2_INCLUDE_DIR GLES3/gl3.h 70 | /usr/openwin/share/include 71 | /opt/graphics/OpenGL/include /usr/X11R6/include 72 | /usr/include 73 | ) 74 | 75 | FIND_LIBRARY(OPENGLES3_gl_LIBRARY 76 | NAMES GLESv2 77 | PATHS /opt/graphics/OpenGL/lib 78 | /usr/openwin/lib 79 | /usr/shlib /usr/X11R6/lib 80 | /usr/lib 81 | ) 82 | 83 | FIND_PATH(EGL_INCLUDE_DIR EGL/egl.h 84 | /usr/openwin/share/include 85 | /opt/graphics/OpenGL/include /usr/X11R6/include 86 | /usr/include 87 | ) 88 | 89 | FIND_LIBRARY(EGL_egl_LIBRARY 90 | NAMES EGL 91 | PATHS /opt/graphics/OpenGL/lib 92 | /usr/openwin/lib 93 | /usr/shlib /usr/X11R6/lib 94 | /usr/lib 95 | ) 96 | 97 | # On Unix OpenGL most certainly always requires X11. 98 | # Feel free to tighten up these conditions if you don't 99 | # think this is always true. 100 | # It's not true on OSX. 101 | 102 | IF (OPENGLES3_gl_LIBRARY) 103 | IF(NOT X11_FOUND) 104 | INCLUDE(FindX11) 105 | ENDIF(NOT X11_FOUND) 106 | IF (X11_FOUND) 107 | IF (NOT APPLE) 108 | SET (OPENGLES3_LIBRARIES ${X11_LIBRARIES}) 109 | ENDIF (NOT APPLE) 110 | ENDIF (X11_FOUND) 111 | ENDIF (OPENGLES3_gl_LIBRARY) 112 | 113 | ENDIF(APPLE) 114 | ENDIF (WIN32) 115 | 116 | SET( OPENGLES3_FOUND "YES" ) 117 | IF(OPENGLES3_gl_LIBRARY AND EGL_egl_LIBRARY) 118 | 119 | SET( OPENGLES3_LIBRARIES ${OPENGLES3_gl_LIBRARY} ${OPENGLES3_LIBRARIES}) 120 | SET( EGL_LIBRARIES ${EGL_egl_LIBRARY} ${EGL_LIBRARIES}) 121 | SET( OPENGLES3_FOUND "YES" ) 122 | 123 | ENDIF(OPENGLES3_gl_LIBRARY AND EGL_egl_LIBRARY) 124 | 125 | MARK_AS_ADVANCED( 126 | OPENGLES3_INCLUDE_DIR 127 | OPENGLES3_gl_LIBRARY 128 | EGL_INCLUDE_DIR 129 | EGL_egl_LIBRARY 130 | ) 131 | -------------------------------------------------------------------------------- /CMakeScripts/Modules/FindPopt.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find Popt 2 | # Once done this will define 3 | # 4 | # POPT_FOUND - system has Popt 5 | # POPT_INCLUDE_DIRS - the Popt include directory 6 | # POPT_LIBRARIES - Link these to use Popt 7 | # POPT_DEFINITIONS - Compiler switches required for using Popt 8 | # 9 | # Copyright (c) 2008 Joshua L. Blocher 10 | # 11 | # Redistribution and use is allowed according to the terms of the New 12 | # BSD license. 13 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 14 | # 15 | 16 | 17 | if (POPT_LIBRARIES AND POPT_INCLUDE_DIRS) 18 | # in cache already 19 | set(POPT_FOUND TRUE) 20 | else (POPT_LIBRARIES AND POPT_INCLUDE_DIRS) 21 | # use pkg-config to get the directories and then use these values 22 | # in the FIND_PATH() and FIND_LIBRARY() calls 23 | if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 24 | include(UsePkgConfig) 25 | pkgconfig(popt _POPT_INCLUDEDIR _POPT_LIBDIR _POPT_LDFLAGS _POPT_CFLAGS) 26 | else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 27 | find_package(PkgConfig) 28 | if (PKG_CONFIG_FOUND) 29 | pkg_check_modules(_POPT popt) 30 | endif (PKG_CONFIG_FOUND) 31 | endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4) 32 | find_path(POPT_INCLUDE_DIR 33 | NAMES 34 | popt.h 35 | PATHS 36 | ${_POPT_INCLUDEDIR} 37 | /usr/include 38 | /usr/local/include 39 | /opt/local/include 40 | /sw/include 41 | $ENV{DEVLIBS_PATH}//include// 42 | PATH_SUFFIXES 43 | popt 44 | ) 45 | 46 | find_library(POPT_LIBRARY 47 | NAMES 48 | popt 49 | PATHS 50 | ${_POPT_LIBDIR} 51 | /lib 52 | /usr/lib 53 | /usr/local/lib 54 | /opt/local/lib 55 | /sw/lib 56 | ) 57 | 58 | if (POPT_LIBRARY) 59 | set(POPT_FOUND TRUE) 60 | endif (POPT_LIBRARY) 61 | 62 | set(POPT_INCLUDE_DIRS 63 | ${POPT_INCLUDE_DIR} 64 | ) 65 | 66 | if (POPT_FOUND) 67 | set(POPT_LIBRARIES 68 | ${POPT_LIBRARIES} 69 | ${POPT_LIBRARY} 70 | ) 71 | endif (POPT_FOUND) 72 | 73 | if (POPT_INCLUDE_DIRS AND POPT_LIBRARIES) 74 | set(POPT_FOUND TRUE) 75 | endif (POPT_INCLUDE_DIRS AND POPT_LIBRARIES) 76 | 77 | if (POPT_FOUND) 78 | if (NOT Popt_FIND_QUIETLY) 79 | message(STATUS "Found Popt: ${POPT_LIBRARIES}") 80 | endif (NOT Popt_FIND_QUIETLY) 81 | else (POPT_FOUND) 82 | if (Popt_FIND_REQUIRED) 83 | message(FATAL_ERROR "Could not find Popt") 84 | endif (Popt_FIND_REQUIRED) 85 | endif (POPT_FOUND) 86 | 87 | # show the POPT_INCLUDE_DIRS and POPT_LIBRARIES variables only in the advanced view 88 | mark_as_advanced(POPT_INCLUDE_DIRS POPT_LIBRARIES) 89 | 90 | endif (POPT_LIBRARIES AND POPT_INCLUDE_DIRS) 91 | 92 | -------------------------------------------------------------------------------- /CMakeScripts/Modules/FindSkia.cmake: -------------------------------------------------------------------------------- 1 | # Find the Skia library 2 | # 3 | # This defines: 4 | # 5 | # SKIA_FOUND 6 | # SKIA_INCLUDE_DIRS 7 | # SKIA_LIBRARIES 8 | 9 | message("Looking for skia...") 10 | set(SKIA_BUILD_DIR "" CACHE PATH "Skia build directory") 11 | 12 | find_library(SKIA_LIBRARIES 13 | NAMES skia 14 | PATHS 15 | ${SKIA_BUILD_DIR}/out/Release 16 | ${SKIA_BUILD_DIR}/trunk/out/Release 17 | $ENV{SKIA_DIR}/lib 18 | $ENV{SKIA_DIR} 19 | /usr/local/lib 20 | /usr/lib 21 | /opt/lib 22 | ) 23 | find_path(SKIA_INCLUDE_DIR 24 | NAMES core/SkCanvas.h 25 | PATH_SUFFIXES skia 26 | PATHS 27 | ${SKIA_BUILD_DIR}/include 28 | ${SKIA_BUILD_DIR}/trunk/include 29 | $ENV{SKIA_DIR}/include 30 | $ENV{SKIA_DIR} 31 | /usr/local/include 32 | /usr/include 33 | /opt/include 34 | ) 35 | 36 | if (SKIA_INCLUDE_DIR) 37 | message("Found include base ${SKIA_INCLUDE_DIR}") 38 | endif (SKIA_INCLUDE_DIR) 39 | 40 | 41 | set(SKIA_INCLUDE_DIRS "") 42 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/) 43 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/core/) 44 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/config/) 45 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/effects/) 46 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/utils/) 47 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/tools/flags/) 48 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/lazy/) 49 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/gpu/) 50 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/gpu/gl/) 51 | list(APPEND SKIA_INCLUDE_DIRS ${SKIA_INCLUDE_DIR}/../src/effects/) 52 | 53 | if (SKIA_LIBRARIES) 54 | message("Found libraries") 55 | endif (SKIA_LIBRARIES) 56 | 57 | if (SKIA_INCLUDE_DIRS) 58 | message("Found includes") 59 | endif (SKIA_INCLUDE_DIRS) 60 | 61 | set (SKIA_FOUND "NO") 62 | if (SKIA_LIBRARIES AND SKIA_INCLUDE_DIRS) 63 | set (SKIA_FOUND "YES") 64 | else (SKIA_LIBRARIES AND SKIA_INCLUDE_DIRS) 65 | if (Skia_FIND_REQUIRED) 66 | message(FATAL_ERROR "Could not find Skia") 67 | endif (Skia_FIND_REQUIRED) 68 | endif (SKIA_LIBRARIES AND SKIA_INCLUDE_DIRS) 69 | 70 | message("Done looking at skia") 71 | -------------------------------------------------------------------------------- /CMakeScripts/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 2 | MESSAGE(FATAL_ERROR "Cannot find install manifest: "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt"") 3 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | 5 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 6 | STRING(REGEX REPLACE " " ";" files "${files}") 7 | STRING(REGEX REPLACE "\n" ";" files "${files}") 8 | FOREACH(file ${files}) 9 | MESSAGE(STATUS "Uninstalling "$ENV{DESTDIR}${file}"") 10 | IF(EXISTS "$ENV{DESTDIR}${file}") 11 | EXEC_PROGRAM( 12 | "@CMAKE_COMMAND@" ARGS "-E remove "$ENV{DESTDIR}${file}"" 13 | OUTPUT_VARIABLE rm_out 14 | RETURN_VALUE rm_retval 15 | ) 16 | IF(NOT "${rm_retval}" STREQUAL 0) 17 | MESSAGE(FATAL_ERROR "Problem when removing "$ENV{DESTDIR}${file}"") 18 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 19 | ELSE(EXISTS "$ENV{DESTDIR}${file}") 20 | MESSAGE(STATUS "File "$ENV{DESTDIR}${file}" does not exist.") 21 | ENDIF(EXISTS "$ENV{DESTDIR}${file}") 22 | ENDFOREACH(file) 23 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright © 2014 Samsung Research America, Silicon Valley. 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holders nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ezhangle/caskbench/dc28549f493526a4eb5ebf2300097fefc9e14868/ChangeLog -------------------------------------------------------------------------------- /HACKING: -------------------------------------------------------------------------------- 1 | Adding New Tests 2 | ================ 3 | Tests are easy to add. Decide a name for the test, then implement these 4 | three routines in cairo-tests/${name}.cpp: 5 | 6 | * ca_setup_${name} 7 | * ca_teardown_${name} 8 | * ca_test_${name} 9 | 10 | The setup routine is executed just once, before the main iterations 11 | begin. For tests that are directly measuring low level drawing 12 | operations, you may not have much - if any - setup. But you could use 13 | this for one-time setup or precalculations that would be expensive to do 14 | in the test proper and that shouldn't be charged against performance. 15 | 16 | Now reimplement the same test for skia (and any other drawing 17 | libraries), with the same three routines but prefixed with sk_*. 18 | 19 | 20 | Adding New Rendering Backends 21 | ============================= 22 | Tasks for adding another backend: 23 | 24 | * cairo-[backend].cpp - surface creation/update/destruction 25 | * skia-[backend].cpp - surface creation/update/destruction 26 | * [backend].cpp - shared code for both of the above 27 | * caskbench-context.cpp - register your backend 28 | * caskbench.cpp - add command line options you need 29 | 30 | 31 | Adding New Drawing Library Backends 32 | =================================== 33 | Adding a new drawing library is a bit more involved: 34 | 35 | * config.h.cmake 36 | * CMakeScripts/Modules/FindXxx.cmake 37 | * CMakeLists.txt - add library to build system 38 | 39 | * caskbench.cpp - add command line options, etc. 40 | * caskbench_context.* - register your drawing library 41 | * [drawlib]-[backend].cpp - surface creation/update/deletion 42 | * [drawlib]-shapes.* - implement shape drawing 43 | * [drawlib]-utils.cpp - misc. routines 44 | * [drawlib]-tests/*.cpp - reimplement all tests 45 | 46 | Start by adding your library to the build system via the cmake files. 47 | The FindXxx.cmake module searches through lists of paths where your 48 | drawing library might be, and figures out the XXX_LIBRARIES path and 49 | XXX_INCLUDE_DIR. It should set XXX_FOUND to "YES" if the library was 50 | detected. Use the cairo and skia modules as examples. Now add a USE_XXX 51 | for your library to config.h.cmake, and then register your library in 52 | CMakeLists.txt - you can basically just copy the logic for cairo. Run 53 | cmake and verify things get detected correctly. 54 | 55 | With the actual coding, the easiest place to start is probably the 56 | command line arguments in caskbench.cpp. Add your library to 57 | print_drawing_libs_available() and update process_drawing_libs() to 58 | check for your drawing library's name. You should now be able to invoke 59 | caskbench with your drawing library specified, and it'll bail out when 60 | it can't find the matching tests. 61 | 62 | We can go ahead and stub in all the tests at this point. Create a 63 | directory src/xxx-tests/ and add the following code to line.cpp: 64 | 65 | #include 66 | int xx_setup_line() { return 1; } 67 | void xx_teardown_line() { } 68 | int xx_test_line { return 1; } 69 | 70 | Copy this file to all the other tests, substituting the test name for 71 | 'line' in the filename and the above three lines. 72 | 73 | Then in the generate_tests bash script, add code to write the 74 | declarations for these tests, and to set up the perf_tests data 75 | structure. To test this part is working, run: 76 | 77 | $ src/generate_tests src/ /dev/stdout 78 | 79 | Now go back to caskbench.cpp and extend populate_user_tests() with your 80 | drawing library. 81 | 82 | 83 | Next, enable your new drawing library in caskbench_context.cpp by adding 84 | definitions for these routines: 85 | 86 | context_setup_xxx() 87 | context_destroy_xxx() 88 | context_update_xxx() 89 | 90 | These three routines are called indirectly from caskbench.cpp's main 91 | routine; it will probably help to review the DESIGN document to learn 92 | how all these bits interoperate. As you implement these three routines, 93 | you'll add your own xxx-egl.cpp and xxx-image.cpp with your 94 | backend-specific code. Use cairo-egl.cpp and cairo-image.cpp as 95 | examples. 96 | 97 | Also add these two routines to xxx-util.cpp: 98 | [Maybe all the drawing lib context routines should be moved to -utils?] 99 | 100 | context_clear_xxx() 101 | write_image_file_xxx() 102 | 103 | 104 | Now you're ready to create a shapes library, xxx-shapes.cpp. This 105 | should be a pretty paint-by-numbers reimplementing of the cairo or 106 | skia shape library. 107 | 108 | Finally, go through and fill in all the tests. This should also be 109 | pretty straightforward. 110 | 111 | -------------------------------------------------------------------------------- /KNOWN_ISSUES: -------------------------------------------------------------------------------- 1 | ~= Known Issues =~ 2 | 3 | * On Ubuntu 12.04 with the -radeon video driver, 'caskbench -t egl' 4 | won't work due to MSAA being unsupported by mesa. So run it with 5 | sample buffers disabled: 6 | 7 | caskbench -t egl --disable-egl-sample-buffers 8 | 9 | * Memory corruption errors can occur when using a Debug version of skia 10 | with a Release version of caskbench, on some platforms. Stick with 11 | Debug/Debug for both to be safe. (Issue #14) 12 | 13 | * On some (older?) versions of Skia, building a Debug caskbench against 14 | a Release build of skia can lead to crashes in SkBitmap::getTexture() 15 | Stick with Debug/Debug or Release/Release, or update to newer Skia. 16 | (Issue #14) 17 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | 0.5 - August 29, 2014 2 | --------------------- 3 | Many more tests are available now, in particular a number of tests have 4 | been adapted from the FlashCanvas testsuite, providing Caskbench with a 5 | wider coverage than previously, and a test scoring mechanism. A number 6 | of tests have also received major re-work and produce better results 7 | than past releases. 8 | 9 | Caskbench is now Open Source! We've moved to a public repository in 10 | github, and hope this enables new contributions from the wider 11 | community. 12 | 13 | 14 | 0.4 - April 25, 2014 15 | -------------------- 16 | Building on last release's preliminary porting of Caskbench to Tizen and 17 | multiple PC variants, a major focus of this release was to get EGL 18 | working on Tizen (and PC) with MSAA enabled. GLX support has been 19 | disabled for this release; it will make a reappearance next release. 20 | 21 | Previous releases have built against an old version of Skia, and this 22 | release will still work with that Skia version (be sure to specify 23 | ENABLE_LEGACY_SKIA_SRA=ON to cmake when configuring). But now Caskbench 24 | also builds and runs against a recent (April 17th) snapshot of Skia as 25 | well. 26 | 27 | Running Caskbench against the older skia-sra branch works pretty solidly 28 | now. There are still some glitches when using the newer skia-samsung 29 | branch, but the numbers will be more relevant for our performance work, 30 | and this will be our development focus going forward. 31 | 32 | This release also includes support for building against CairoGles, a 33 | fork of upstream Cairo by Samsung which includes various GL 34 | optimizations, GLES enablement and new features. It is off by default 35 | but can be configured on by passing ENABLE_CAIROGLES=ON to cmake. 36 | 37 | Tests now write out the last frame to a file. This allows comparison of 38 | skia and cairo rendering functionality, so that discrepancies are 39 | obvious. Several tests have been expanded, and others newly added; much 40 | of this is still experimental though, but lay a good foundation for the 41 | 0.5 release's primary focus on expansion of test coverage. A few tests 42 | are disabled in this release due to stability concerns with the newer 43 | skia library, and will make a return in 0.5. 44 | 45 | 46 | 47 | 0.3 - January 13, 2014 48 | ---------------------- 49 | A major focus of this release was porting to all target platforms. It 50 | compiles and runs on PC (Linux) and ARM (Tizen), and supports software 51 | rendering (image), GLX, EGL/GLES 2, and EGL/GLES 3. If GLX or EGL is 52 | not present on the system, caskbench will compile and run without it. 53 | 54 | A few new tests have been added, and existing ones tweaked for 55 | improvement. Note though that there are still a few discrepancies 56 | between the skia and cairo implementations of individual tests, so the 57 | test results are questionable and will need deeper study to be of 58 | use. The next release will focus on addressing these deficiencies and 59 | improving the quality of the tests. 60 | 61 | 62 | 0.2 - November 8, 2013 63 | ---------------------- 64 | This release provides improved Cairo tests and matching Skia tests. 65 | Both are run with a common `caskbench` executable, and results tabulated 66 | to stdout or optionally written to a JSON file. 67 | 68 | The Skia cmake integration is still incomplete, in that paths are 69 | hardcoded to my own environment. These will be cleaned up in future 70 | releases. The main priority was to get everything running on my own 71 | system. 72 | 73 | 74 | 0.1 - November 1, 2013 75 | ---------------------- 76 | Initial release. Cairo tests have been stubbed in, but it's got a long 77 | way to go before it's usable. 78 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | caskbench - The Cairo and Skia Benchmark 2 | ======================================== 3 | 4 | This benchmark is designed to do synthetic performance testing of 5 | the cairo and skia drawing libraries. 6 | 7 | Our principle goal is to identify problem areas in either of the drawing 8 | libraries for performance work to be done. To this end, we enable large 9 | scale randomized testing of a broad range of drawing features, but 10 | document the parameters so that particular problem cases can easily be 11 | run in isolation for performance work. 12 | 13 | This test suite strives to provide a flexible performance testing 14 | toolbox useful for a range of test cases from low level performance 15 | optimization work to high level benchmarking of devices. 16 | 17 | 18 | == Building == 19 | 20 | Prerequisites include popt and gles3. To install these on Ubuntu 13.04: 21 | 22 | $ sudo apt-get install libpopt-dev libgles2-mesa-dev 23 | 24 | You will also need Skia and a GL-enabled version of libcairo installed. 25 | These aren't packaged for Ubuntu currently, so you'll need to build from 26 | source. 27 | 28 | To build this testsuite, use these commands: 29 | 30 | $ cmake . 31 | $ make 32 | 33 | The build system looks for the skia library in /usr/lib and 34 | /usr/local/lib, and header files in /usr/include/skia and 35 | /usr/local/include/skia. 36 | 37 | A number of configuration settings can be overridden through cmake. To 38 | see a list of the options available for caskbench run: 39 | 40 | $ cmake -L 41 | 42 | or, for more advanced cmake settings: 43 | 44 | $ cmake --help 45 | 46 | For example, to build caskbench with only Cairo and no Skia at all, do: 47 | 48 | $ cmake . -DENABLE_SKIA=OFF 49 | 50 | 51 | == Usage == 52 | 53 | Caskbench builds to a single executable which you can run directly 54 | (using the software renderer): 55 | 56 | $ ./src/caskbench 57 | 58 | cairo-bubbles 64 PASS 10 115.60 59 | skia-bubbles 64 PASS 10 311.93 62.94% 60 | ... 61 | 62 | The testing will alternate between cairo and skia versions of each test. 63 | The second column indicates the test size, the fourth column is the 64 | number of iterations. If the third column shows anything other than a 65 | pass, something's seriously wrong. The fifth column is the fps value. 66 | The last column calculates the percent difference that skia is faster 67 | than cairo on average. 68 | 69 | For hardware acceleration, specify the surface type to use (e.g. glx or 70 | egl) via the -t parameter. 71 | 72 | $ ./src/caskbench -t egl 73 | 74 | You can learn the available surface types via --list-surfaces: 75 | 76 | $ ./src/caskbench --list-surfaces 77 | 78 | image 79 | egl 80 | 81 | The --iterations and --size parameters can be used to increase the 82 | intensity of the testing. 83 | 84 | $ ./src/caskbench -t egl --iterations 100 --size 42 85 | 86 | Run it with the '-?' flag to see usage directions with explanations of 87 | all available options. 88 | 89 | Caskbench is tested with the following skia branches: 90 | 1. https://github.com/Samsung/skia/tree/dev/m34_1847 91 | 2. https://github.com/Samsung/skia/tree/dev/m36_1985 92 | 3. https://github.com/Samsung/skia/tree/upstream/m34_1847 93 | 4. https://github.com/Samsung/skia/tree/upstream/m36_1985 94 | 5. https://github.com/Samsung/skia/tree/henry 95 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | 2 | * Add support for comparing with OpenVG 3 | * Add support for comparing with fog - http://code.google.com/p/fog/ 4 | * Add support for comparing with Azure 5 | * Add xcb backend 6 | + http://lists.cairographics.org/archives/cairo/2008-June/014334.html 7 | + http://marc.info/?l=cairo&m=121114572422121 8 | + http://xcb.freedesktop.org/tutorial/ 9 | -------------------------------------------------------------------------------- /config.h.cmake: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H_ 2 | #define _CONFIG_H_ 3 | 4 | #cmakedefine HAVE_GLES2_H 1 5 | #cmakedefine HAVE_GLES3_H 1 6 | #cmakedefine HAVE_GLX_H 1 7 | #cmakedefine HAVE_CAIRO_GL_H 1 8 | #cmakedefine USE_SKIA 1 9 | #cmakedefine USE_CAIRO 1 10 | #cmakedefine USE_EGL 1 11 | #cmakedefine USE_GLX 0 12 | #cmakedefine USE_CAIROGLES 0 13 | 14 | #define PACKAGE "${PROJECT_NAME}" 15 | #define PACKAGE_NAME "${PROJECT_NAME}" 16 | #define PACKAGE_VERSION "${PROJECT_VERSION}" 17 | #define PACKAGE_STRING "${PROJECT_NAME} ${PROJECT_VERSION}" 18 | 19 | // Workarounds for skia packaging bug 20 | #define SK_ATOMICS_PLATFORM_H "ports/SkAtomics_sync.h" 21 | #define SK_MUTEX_PLATFORM_H "ports/SkMutex_pthread.h" 22 | #define SK_ENABLE_INST_COUNT 0 23 | 24 | #endif /* _CONFIG_H_ */ 25 | -------------------------------------------------------------------------------- /packaging/caskbench.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /packaging/caskbench.spec: -------------------------------------------------------------------------------- 1 | # 2 | Name: caskbench 3 | Summary: Cairo and Skia Benchmark 4 | Version: 0.5.0 5 | Release: 1.0 6 | Group: Graphics & UI Framework/Testing 7 | ExcludeArch: i596 8 | License: GPL 9 | URL: http://www.x.org/ 10 | Source0: %{name}-%{version}.tar.bz2 11 | Source1001: packaging/caskbench.manifest 12 | 13 | Requires: xorg-x11-server-Xorg 14 | 15 | BuildRequires: cmake 16 | BuildRequires: gcc-c++ 17 | BuildRequires: rpm-devel 18 | BuildRequires: popt-devel 19 | BuildRequires: pkgconfig(fontconfig) 20 | BuildRequires: pkgconfig(freetype2) 21 | BuildRequires: pkgconfig(x11) 22 | BuildRequires: pkgconfig(opengl-es-20) 23 | BuildRequires: pkgconfig(gles20) 24 | BuildRequires: pkgconfig(cairo) >= 1.12.0 25 | BuildRequires: skia 26 | 27 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-build 28 | 29 | %description 30 | Cairo and Skia benchmark 31 | 32 | %prep 33 | %setup -q -n %{name}-%{version} 34 | 35 | %build 36 | mkdir build 37 | cd build 38 | export CFLAGS="$RPM_OPT_FLAGS" 39 | export CXXFLAGS="$CFLAGS" 40 | 41 | cmake $CMAKE_FLAGS \ 42 | -DCMAKE_INSTALL_PREFIX=/usr \ 43 | -DDOC_INSTALL_DIR=%{_docdir} \ 44 | -DLIB=%{_lib} \ 45 | -DCMAKE_VERBOSE_MAKEFILE=TRUE \ 46 | -DCMAKE_BUILD_TYPE=Release \ 47 | .. 48 | 49 | make %{?jobs:-j %jobs} VERBOSE=1 50 | 51 | %install 52 | rm -rf %{buildroot} 53 | mkdir -p %{buildroot}/usr/share/license 54 | cd build 55 | make install DESTDIR=$RPM_BUILD_ROOT 56 | cd .. 57 | cp COPYING %{buildroot}/usr/share/license/%{name} 58 | 59 | 60 | %clean 61 | rm -rf "$RPM_BUILD_ROOT" 62 | 63 | %files 64 | %manifest packaging/caskbench.manifest 65 | %defattr(-,root,root,-) 66 | %{_bindir}/caskbench 67 | /usr/share/license/%{name} 68 | 69 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB caskbench_SOURCES 2 | caskbench.cpp 3 | caskbench_context.cpp 4 | caskbench_result.cpp 5 | kinetics.cpp 6 | image.cpp 7 | shapes.cpp 8 | rnd.cpp 9 | ) 10 | 11 | if (USE_GLX) 12 | list(APPEND caskbench_SOURCES 13 | glx.cpp 14 | ) 15 | endif (USE_GLX) 16 | 17 | if (USE_EGL) 18 | list(APPEND caskbench_SOURCES 19 | egl.cpp 20 | ) 21 | endif (USE_EGL) 22 | 23 | if (USE_SKIA) 24 | file(GLOB skia_files 25 | skia-util.cpp 26 | skia-image.cpp 27 | skia-shapes.cpp 28 | skia-tests/*.cpp 29 | ) 30 | list(APPEND caskbench_SOURCES ${skia_files} ) 31 | if (USE_GLX) 32 | list(APPEND caskbench_SOURCES skia-glx.cpp) 33 | endif (USE_GLX) 34 | if (USE_EGL) 35 | list(APPEND caskbench_SOURCES skia-egl.cpp) 36 | endif (USE_EGL) 37 | endif (USE_SKIA) 38 | 39 | if (USE_CAIRO) 40 | file(GLOB cairo_files 41 | cairo-util.cpp 42 | cairo-image.cpp 43 | cairo-shapes.cpp 44 | cairo-tests/*.cpp 45 | ) 46 | list(APPEND caskbench_SOURCES ${cairo_files} ) 47 | if (USE_GLX) 48 | list(APPEND caskbench_SOURCES cairo-glx.cpp) 49 | endif (USE_GLX) 50 | if (USE_EGL) 51 | list(APPEND caskbench_SOURCES cairo-egl.cpp) 52 | endif (USE_EGL) 53 | endif (USE_CAIRO) 54 | 55 | add_executable(generate_tests IMPORTED) 56 | set_property(TARGET generate_tests PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/generate_tests") 57 | 58 | add_executable(generate_git_info IMPORTED) 59 | set_property(TARGET generate_git_info PROPERTY IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/generate_git_info") 60 | 61 | set(GENERATED_TESTS ${CMAKE_CURRENT_BINARY_DIR}/tests.cpp) 62 | set(GIT_INFO ${CMAKE_CURRENT_BINARY_DIR}/git_info.cpp) 63 | 64 | add_custom_command( 65 | OUTPUT ${GENERATED_TESTS} 66 | COMMAND generate_tests ${CMAKE_CURRENT_SOURCE_DIR} ${GENERATED_TESTS} 67 | ) 68 | 69 | add_custom_command( 70 | OUTPUT ${GIT_INFO} 71 | COMMAND generate_git_info ${CMAKE_CURRENT_SOURCE_DIR} ${GIT_INFO} 72 | ) 73 | list(APPEND caskbench_SOURCES 74 | ${GENERATED_TESTS} 75 | ${GIT_INFO} 76 | ) 77 | add_executable(caskbench ${caskbench_SOURCES}) 78 | target_link_libraries(caskbench ${CASKBENCH_LIBS}) 79 | -------------------------------------------------------------------------------- /src/cairo-egl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #if HAVE_GLES3_H 16 | #include 17 | #elif HAVE_GLES2_H 18 | #include 19 | #endif 20 | 21 | #include "egl.h" 22 | #include "device_config.h" 23 | 24 | static egl_state_t *state; 25 | static cairo_surface_t *cairo_surface; 26 | 27 | cairo_surface_t * 28 | create_cairo_surface_egl (const device_config_t& config) 29 | { 30 | cairo_device_t *cairo_device; 31 | 32 | state = (egl_state_t*) malloc (sizeof (egl_state_t)); 33 | if (!state) { 34 | warnx ("Out of memory\n"); 35 | return NULL; 36 | } 37 | 38 | if (!createEGLContextAndWindow(state, config)) { 39 | cleanup_state_egl(state); 40 | errx (-1, "Could not create EGL context and window\n"); 41 | } 42 | 43 | eglMakeCurrent(state->egl_display, state->egl_surface, state->egl_surface, state->egl_context); 44 | 45 | cairo_device = cairo_egl_device_create (state->egl_display, state->egl_context); 46 | cairo_status_t status = cairo_device_status (cairo_device); 47 | if (status != CAIRO_STATUS_SUCCESS) 48 | errx (-1, "Could not create EGL device: (%d) %s\n", status, cairo_status_to_string (status) ); 49 | 50 | cairo_gl_device_set_thread_aware (cairo_device, 0); 51 | cairo_surface = cairo_gl_surface_create_for_egl (cairo_device, 52 | state->egl_surface, 53 | config.width, config.height); 54 | 55 | cairo_device_destroy (cairo_device); 56 | 57 | glClearColor(1, 1, 1, 1); 58 | glClear(GL_COLOR_BUFFER_BIT); 59 | 60 | return cairo_surface; 61 | } 62 | 63 | void 64 | destroy_cairo_egl(void) 65 | { 66 | //cairo_surface_destroy (cairo_surface); 67 | cleanup_state_egl (state); 68 | } 69 | 70 | void 71 | update_cairo_egl(void) 72 | { 73 | //eglSwapBuffers(state->egl_display, state->egl_surface); 74 | cairo_gl_surface_swapbuffers (cairo_surface); 75 | } 76 | 77 | /* 78 | Local Variables: 79 | mode:c++ 80 | c-file-style:"stroustrup" 81 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 82 | indent-tabs-mode:nil 83 | fill-column:99 84 | End: 85 | */ 86 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 87 | -------------------------------------------------------------------------------- /src/cairo-glx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | 15 | #include "glx.h" 16 | #include "device_config.h" 17 | 18 | static glx_state_t *state; 19 | 20 | cairo_surface_t * 21 | create_cairo_surface_glx (const device_config_t& config) 22 | { 23 | cairo_device_t *cairo_device; 24 | cairo_surface_t *cairo_surface; 25 | 26 | state = (glx_state_t*) malloc (sizeof (glx_state_t)); 27 | if (!state) { 28 | warnx ("Out of memory\n"); 29 | return NULL; 30 | } 31 | 32 | if (!createGLXContextAndWindow(state, config.width, config.height)) { 33 | cleanup_state_glx(state); 34 | errx (-1, "Could not create GLX context and window\n"); 35 | } 36 | 37 | cairo_device = cairo_glx_device_create (state->dpy, state->glx_context); 38 | cairo_status_t status = cairo_device_status (cairo_device); 39 | if (status != CAIRO_STATUS_SUCCESS) 40 | errx (-1, "Could not create GLX device: (%d) %s\n", status, cairo_status_to_string (status) ); 41 | 42 | cairo_gl_device_set_thread_aware (cairo_device, 0); 43 | cairo_surface = cairo_gl_surface_create_for_window (cairo_device, 44 | state->window, 45 | config.width, config.height); 46 | cairo_device_destroy (cairo_device); 47 | 48 | glClearColor(1, 1, 1, 1); 49 | glClear(GL_COLOR_BUFFER_BIT); 50 | 51 | return cairo_surface; 52 | } 53 | 54 | void 55 | destroy_cairo_glx(void) 56 | { 57 | cleanup_state_glx(state); 58 | } 59 | 60 | void 61 | update_cairo_glx(void) 62 | { 63 | cairo_gl_surface_swapbuffers (cairo_surface); 64 | } 65 | 66 | /* 67 | Local Variables: 68 | mode:c++ 69 | c-file-style:"stroustrup" 70 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 71 | indent-tabs-mode:nil 72 | fill-column:99 73 | End: 74 | */ 75 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 76 | -------------------------------------------------------------------------------- /src/cairo-image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "forward.h" 15 | #include "image.h" 16 | 17 | static image_state_t *state; 18 | cairo_surface_t *cairo_surface; 19 | 20 | static bool 21 | convert_cairo_surface_to_ximage (cairo_surface_t *surface) 22 | { 23 | unsigned char *data = cairo_image_surface_get_data (surface); 24 | state->image.width = cairo_image_surface_get_width (surface); 25 | state->image.height = cairo_image_surface_get_height (surface); 26 | state->image.format = ZPixmap; 27 | state->image.data = (char*)data; 28 | state->image.bitmap_unit = 4 * 8; 29 | state->image.byte_order = LSBFirst; 30 | state->image.bitmap_bit_order = LSBFirst; 31 | state->image.bitmap_pad = 4 * 8; 32 | state->image.depth = 32; 33 | state->image.bytes_per_line = state->image.width * 4; 34 | state->image.bits_per_pixel = 4 * 8; 35 | return XInitImage (&state->image); 36 | } 37 | 38 | cairo_surface_t * 39 | create_cairo_surface_image (const device_config_t& config) 40 | { 41 | state = (image_state_t*) malloc (sizeof (image_state_t)); 42 | if (!state) { 43 | warnx ("Out of memory\n"); 44 | return NULL; 45 | } 46 | 47 | if (!createImageWindow(state, config)) { 48 | cleanup_state_image(state); 49 | return NULL; 50 | } 51 | 52 | cairo_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 53 | config.width, 54 | config.height); 55 | 56 | return cairo_surface; 57 | } 58 | 59 | void 60 | destroy_cairo_image(void) 61 | { 62 | destroyImageWindow(state); 63 | cleanup_state_image(state); 64 | } 65 | 66 | void 67 | update_cairo_image(void) 68 | { 69 | if (convert_cairo_surface_to_ximage (cairo_surface)) { 70 | updateImageWindow(state); 71 | } 72 | } 73 | 74 | /* 75 | Local Variables: 76 | mode:c++ 77 | c-file-style:"stroustrup" 78 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 79 | indent-tabs-mode:nil 80 | fill-column:99 81 | End: 82 | */ 83 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 84 | -------------------------------------------------------------------------------- /src/cairo-shapes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __CAIRO_SHAPES_H_ 8 | #define __CAIRO_SHAPES_H_ 9 | 10 | #include "forward.h" 11 | #include "shapes.h" 12 | #include "caskbench.h" 13 | 14 | void cairoRandomizeColor(caskbench_context_t *cr); 15 | 16 | void ca_set_fill_style(caskbench_context_t *ctx, const shapes_t *shape); 17 | 18 | void cairoDrawCircle(caskbench_context_t *ctx, shapes_t *args); 19 | 20 | void cairoDrawRectangle(caskbench_context_t *ctx, shapes_t *args); 21 | 22 | void cairoDrawTriangle(caskbench_context_t *ctx, shapes_t *args); 23 | 24 | void cairoDrawStar(caskbench_context_t *ctx, shapes_t *args); 25 | 26 | void cairoDrawRoundedRectangle (caskbench_context_t *ctx, shapes_t *args); 27 | 28 | void cairoDrawLine(caskbench_context_t *ctx, shapes_t *args); 29 | 30 | void cairoDrawCubicCurve(caskbench_context_t *ctx, shapes_t *args); 31 | 32 | void cairoDrawQuadraticCurve(caskbench_context_t *ctx, shapes_t *args); 33 | 34 | cairo_surface_t *cairoCreateSampleImage (caskbench_context_t *ctx); 35 | 36 | cairo_surface_t *cairoCacheImageSurface(caskbench_context_t *ctx, cairo_surface_t *image); 37 | 38 | extern void (*cairoShapes[CB_SHAPE_END-1])(caskbench_context_t *ctx , shapes_t *args); 39 | 40 | void cairoDrawRandomizedShape(caskbench_context_t *ctx, shapes_t *shape); 41 | 42 | #endif 43 | /* 44 | Local Variables: 45 | mode:c++ 46 | c-file-style:"stroustrup" 47 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 48 | indent-tabs-mode:nil 49 | fill-column:99 50 | End: 51 | */ 52 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 53 | -------------------------------------------------------------------------------- /src/cairo-tests/animation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | #include "kinetics.h" 18 | 19 | static kinetics_t *particles; 20 | 21 | int 22 | ca_setup_animation(caskbench_context_t *ctx) 23 | { 24 | if (ctx->size < 0) 25 | return 0; 26 | 27 | // Animation setup 28 | particles = (kinetics_t *) malloc (sizeof (kinetics_t) * ctx->size); 29 | for (int i = 0; i < ctx->size; i++) 30 | kinetics_init(&particles[i], ctx); 31 | 32 | return 1; 33 | } 34 | 35 | void 36 | ca_teardown_animation(void) 37 | { 38 | free(particles); 39 | } 40 | 41 | int 42 | ca_test_animation(caskbench_context_t *ctx) 43 | { 44 | // Animation / Kinematics of single or multi shape 45 | cairo_set_source_rgb (ctx->cairo_cr, 0, 0, 0); 46 | cairo_rectangle (ctx->cairo_cr, 0, 0, ctx->canvas_width ,ctx->canvas_height); 47 | cairo_fill (ctx->cairo_cr); 48 | 49 | static int counter = 0; 50 | for (int i = 0; i < ctx->size; i++) { 51 | shapes_t shape; 52 | kinetics_t *particle = &particles[i]; 53 | 54 | kinetics_update(particle, 0.1); 55 | 56 | shape_copy(&ctx->shape_defaults, &shape); 57 | shape.width = particle->width; 58 | shape.height = particle->height; 59 | shape.x = particle->x; 60 | shape.y = particle->y; 61 | if (!shape.radius) 62 | shape.radius = 40; 63 | 64 | cairo_save(ctx->cairo_cr); 65 | cairo_rotate(ctx->cairo_cr, counter/50.0); 66 | 67 | cairoDrawRandomizedShape(ctx, &shape); 68 | cairo_restore(ctx->cairo_cr); 69 | 70 | counter++; 71 | } 72 | 73 | return 1; 74 | } 75 | 76 | /* 77 | Local Variables: 78 | mode:c++ 79 | c-file-style:"stroustrup" 80 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 81 | indent-tabs-mode:nil 82 | fill-column:99 83 | End: 84 | */ 85 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 86 | -------------------------------------------------------------------------------- /src/cairo-tests/bubbles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | static int max_dim; 18 | 19 | int 20 | ca_setup_bubbles(caskbench_context_t *ctx) 21 | { 22 | max_dim = MIN(ctx->canvas_width, ctx->canvas_height)/2; 23 | return 1; 24 | } 25 | 26 | void 27 | ca_teardown_bubbles(void) 28 | { 29 | } 30 | 31 | int 32 | ca_test_bubbles(caskbench_context_t *ctx) 33 | { 34 | int i, x, y, r; 35 | cairo_t *cr = ctx->cairo_cr; 36 | 37 | for (i=0; isize; i++) { 38 | cairoRandomizeColor(ctx); 39 | 40 | r = ((double)max_dim*rnd())/RAND_MAX + 1; 41 | x = (0.5*(double)ctx->canvas_width*rnd())/RAND_MAX; 42 | y = (0.5*(double)ctx->canvas_height*rnd())/RAND_MAX; 43 | cairo_arc (cr, x, y, r, 0, 2*M_PI); 44 | cairo_fill (cr); 45 | } 46 | 47 | return 1; 48 | } 49 | 50 | /* 51 | Local Variables: 52 | mode:c++ 53 | c-file-style:"stroustrup" 54 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 55 | indent-tabs-mode:nil 56 | fill-column:99 57 | End: 58 | */ 59 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 60 | -------------------------------------------------------------------------------- /src/cairo-tests/circle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_circle(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_circle(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_circle(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | shape.x = (double)rnd()/RAND_MAX * w; 40 | shape.y = (double)rnd()/RAND_MAX * h; 41 | shape.radius = (double)rnd()/RAND_MAX * MIN( 42 | MIN(shape.x, w-shape.x), MIN(shape.y, h-shape.y)); 43 | 44 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 45 | shape.fill_type = generate_random_fill_type(); 46 | } 47 | ca_set_fill_style(ctx, &shape); 48 | 49 | shape.shape_type = CB_SHAPE_CIRCLE; 50 | cairoDrawRandomizedShape(ctx,&shape); 51 | } 52 | 53 | return 1; 54 | } 55 | 56 | /* 57 | Local Variables: 58 | mode:c++ 59 | c-file-style:"stroustrup" 60 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 61 | indent-tabs-mode:nil 62 | fill-column:99 63 | End: 64 | */ 65 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 66 | -------------------------------------------------------------------------------- /src/cairo-tests/clip.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "caskbench.h" 13 | #include "caskbench_context.h" 14 | #include "cairo-shapes.h" 15 | 16 | static cairo_surface_t *image; 17 | static cairo_surface_t *cached_image; 18 | int 19 | ca_setup_clip(caskbench_context_t *ctx) 20 | { 21 | image = cairoCreateSampleImage (ctx); 22 | cached_image = cairoCacheImageSurface (ctx, image); 23 | return 1; 24 | } 25 | 26 | void 27 | ca_teardown_clip(void) 28 | { 29 | cairo_surface_destroy (image); 30 | cairo_surface_destroy (cached_image); 31 | } 32 | 33 | #if 1 34 | // Single static star and random clip 35 | int 36 | ca_test_clip(caskbench_context_t *ctx) 37 | { 38 | int w = ctx->canvas_width; 39 | int h = ctx->canvas_height; 40 | double ratio; 41 | ratio = (double) w/h; 42 | shapes_t shape; 43 | double scale_param_x = w/80; 44 | double scale_param_y; 45 | cairo_t *cr = ctx->cairo_cr; 46 | 47 | shape_copy(&ctx->shape_defaults, &shape); 48 | cairo_new_path(cr); 49 | cairo_save (cr); 50 | 51 | /* Draw star for the full screen size */ 52 | if (ratio > 1.0) 53 | scale_param_y = scale_param_x * (1/ratio); 54 | else if (ratio < 1.0) 55 | scale_param_y = scale_param_x + (ratio); 56 | else 57 | scale_param_y = scale_param_x; 58 | 59 | cairo_scale (cr, scale_param_x,scale_param_y); 60 | shape.x = 0; 61 | shape.y = 0; 62 | shape.radius = 40; 63 | shape.shape_type = CB_SHAPE_STAR; 64 | shape.fill_type = CB_FILL_SOLID; 65 | 66 | ca_set_fill_style(ctx, &shape); 67 | cairoDrawRandomizedShape(ctx,&shape); 68 | 69 | for (int i=0; isize; i++) { 70 | cairoDrawStar(ctx,&shape); 71 | cairo_clip (cr); 72 | double x1 = (double)rnd()/RAND_MAX * w; 73 | double x2 = (double)rnd()/RAND_MAX * w; 74 | double y1 = (double)rnd()/RAND_MAX * h; 75 | double y2 = (double)rnd()/RAND_MAX * h; 76 | cairo_set_source_surface (cr, cached_image, x1, y1); 77 | // To scale without blur 78 | cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST); 79 | cairo_paint (cr); 80 | cairo_reset_clip(cr); 81 | } 82 | 83 | cairo_restore (cr); 84 | 85 | return 1; 86 | } 87 | #else 88 | // Random stars and random clip 89 | int 90 | ca_test_clip(caskbench_context_t *ctx) 91 | { 92 | int w = ctx->canvas_width; 93 | int h = ctx->canvas_height; 94 | 95 | shapes_t shape; 96 | shape_copy(&ctx->shape_defaults, &shape); 97 | cairo_set_source_rgb (ctx->cairo_cr, 0, 0, 0); 98 | cairo_paint (ctx->cairo_cr); 99 | 100 | cairo_t *cr = ctx->cairo_cr; 101 | for (int i=0; isize; i++) { 102 | double i = (double)rnd()/RAND_MAX * w; 103 | double j = (double)rnd()/RAND_MAX * h; 104 | double x1 = (double)rnd()/RAND_MAX * 80; 105 | double y1 = (double)rnd()/RAND_MAX * 80; 106 | 107 | cairo_new_path(cr); 108 | cairo_save (cr); 109 | cairo_translate (cr,i,j); 110 | cairo_scale(cr,0.5,0.5); 111 | 112 | shape.x = 0; 113 | shape.y = 0; 114 | shape.radius = 40; 115 | shape.shape_type = CB_SHAPE_STAR; 116 | shape.fill_type = CB_FILL_SOLID; 117 | ca_set_fill_style(ctx, &shape); 118 | cairoDrawRandomizedShape(ctx,&shape); 119 | 120 | cairoDrawStar(ctx,&shape); 121 | cairo_clip(cr); 122 | cairo_set_source_surface (cr, image, x1, y1); 123 | cairo_paint (cr); 124 | cairo_reset_clip(cr); 125 | cairo_restore(cr); 126 | } 127 | 128 | return 1; 129 | } 130 | #endif 131 | /* 132 | Local Variables: 133 | mode:c++ 134 | c-file-style:"stroustrup" 135 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 136 | indent-tabs-mode:nil 137 | fill-column:99 138 | End: 139 | */ 140 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 141 | -------------------------------------------------------------------------------- /src/cairo-tests/cubic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_cubic(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_cubic(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_cubic(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | shape.x = (double)rnd()/RAND_MAX * w; 40 | shape.dx1 = (double)rnd()/RAND_MAX * w; 41 | shape.dx2 = (double)rnd()/RAND_MAX * w; 42 | shape.width = (double)rnd()/RAND_MAX * w - shape.x; 43 | shape.y = (double)rnd()/RAND_MAX * h; 44 | shape.dy1 = (double)rnd()/RAND_MAX * h; 45 | shape.dy2 = (double)rnd()/RAND_MAX * h; 46 | shape.height = (double)rnd()/RAND_MAX * h - shape.y; 47 | 48 | cairoRandomizeColor(ctx); 49 | cairoDrawCubicCurve(ctx, &shape); 50 | if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) 51 | cairo_fill(ctx->cairo_cr); 52 | else 53 | cairo_stroke(ctx->cairo_cr); 54 | } 55 | 56 | 57 | return 1; 58 | } 59 | 60 | /* 61 | Local Variables: 62 | mode:c++ 63 | c-file-style:"stroustrup" 64 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 65 | indent-tabs-mode:nil 66 | fill-column:99 67 | End: 68 | */ 69 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 70 | -------------------------------------------------------------------------------- /src/cairo-tests/curves.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | static double delta = 0; 18 | 19 | int 20 | ca_setup_curves(caskbench_context_t *ctx) 21 | { 22 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 23 | cairo_set_line_width (ctx->cairo_cr, 1); 24 | 25 | return 1; 26 | } 27 | 28 | void 29 | ca_teardown_curves(void) 30 | { 31 | } 32 | 33 | int 34 | ca_test_curves(caskbench_context_t *ctx) 35 | { 36 | cairo_t *cr = ctx->cairo_cr; 37 | int cp = ctx->canvas_width / 2; // center point 38 | int rr = ctx->canvas_width / 2; 39 | int nn = 32; // must be even 40 | double step = (2 * M_PI) / nn; 41 | 42 | for (int i=0; isize; i++) { 43 | double angle = delta; // in radians 44 | double x = cp + rr * cos(angle); 45 | double y = cp + rr * sin(angle); 46 | 47 | // begin path 48 | cairo_new_path(cr); 49 | cairo_move_to (cr, x, y); 50 | 51 | // segments 52 | for (int j=0; jcairo_cr, 63 | x1, y1, 64 | x2, y2, x2,y2); 65 | } 66 | cairo_close_path(cr); 67 | cairoRandomizeColor(ctx); 68 | 69 | // TODO: apply other fill types 70 | if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) { 71 | cairo_fill (cr); 72 | } 73 | cairo_stroke (cr); 74 | 75 | } 76 | delta += 0.5; 77 | return 1; 78 | } 79 | 80 | /* 81 | Local Variables: 82 | mode:c++ 83 | c-file-style:"stroustrup" 84 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 85 | indent-tabs-mode:nil 86 | fill-column:99 87 | End: 88 | */ 89 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 90 | -------------------------------------------------------------------------------- /src/cairo-tests/fill.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include "forward.h" 10 | #include "caskbench.h" 11 | #include "caskbench_context.h" 12 | #include "cairo-shapes.h" 13 | 14 | static int element_spacing; 15 | static int num_x_elements; 16 | static int num_y_elements; 17 | 18 | int 19 | ca_setup_fill(caskbench_context_t *ctx) 20 | { 21 | if (ctx->size <= 0) 22 | return 0; 23 | return 1; 24 | } 25 | 26 | void 27 | ca_teardown_fill(void) 28 | { 29 | } 30 | 31 | int 32 | ca_test_fill(caskbench_context_t *ctx) 33 | { 34 | for (int i = 0; i < ctx->size; i++) 35 | { 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | 39 | if (!(shape.x && shape.y)) 40 | { 41 | shape.x = ctx->canvas_width/2; 42 | shape.y = ctx->canvas_height/2; 43 | } 44 | if (!(shape.width && shape.height)) 45 | { 46 | shape.width = 100; 47 | shape.height = 50; 48 | } 49 | if (!shape.radius) 50 | shape.radius = 40; 51 | 52 | /* Height is used for creating patterns, needs to be updated for star and triangle */ 53 | if (shape.shape_type == CB_SHAPE_STAR || shape.shape_type == CB_SHAPE_TRIANGLE) 54 | shape.height = 2*shape.radius; 55 | 56 | /* Use rectangle as default shape */ 57 | shape.shape_type = shape.shape_type ? shape.shape_type:CB_SHAPE_RECTANGLE; 58 | cairoDrawRandomizedShape(ctx, &shape); 59 | } 60 | return 1; 61 | } 62 | 63 | /* 64 | Local Variables: 65 | mode:c++ 66 | c-file-style:"stroustrup" 67 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 68 | indent-tabs-mode:nil 69 | fill-column:99 70 | End: 71 | */ 72 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 73 | -------------------------------------------------------------------------------- /src/cairo-tests/hline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_hline(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_hline(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_hline(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | 40 | double x1 = (double)rnd()/RAND_MAX * w; 41 | double x2 = (double)rnd()/RAND_MAX * w; 42 | double y = (double)rnd()/RAND_MAX * h; 43 | 44 | shape.x = x1; 45 | shape.y = y; 46 | shape.width = x1 - x2; 47 | shape.height = 0; 48 | 49 | cairoRandomizeColor(ctx); 50 | cairoDrawLine(ctx, &shape); 51 | cairo_stroke(ctx->cairo_cr); 52 | } 53 | 54 | return 1; 55 | } 56 | 57 | /* 58 | Local Variables: 59 | mode:c++ 60 | c-file-style:"stroustrup" 61 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 62 | indent-tabs-mode:nil 63 | fill-column:99 64 | End: 65 | */ 66 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 67 | -------------------------------------------------------------------------------- /src/cairo-tests/image-rotate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | #include 9 | 10 | #include "caskbench.h" 11 | #include "caskbench_context.h" 12 | #include "cairo-shapes.h" 13 | 14 | static cairo_surface_t *image; 15 | static cairo_surface_t *cached_image; 16 | 17 | int 18 | ca_setup_image_rotate(caskbench_context_t *ctx) 19 | { 20 | image = cairoCreateSampleImage (ctx); 21 | cached_image = cairoCacheImageSurface (ctx, image); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_image_rotate(void) 27 | { 28 | cairo_surface_destroy (image); 29 | cairo_surface_destroy (cached_image); 30 | } 31 | 32 | int 33 | ca_test_image_rotate(caskbench_context_t* ctx) 34 | { 35 | cairo_t *cr = ctx->cairo_cr; 36 | static int counter = 0; 37 | double radian = 0; 38 | int w = ctx->canvas_width; 39 | int h = ctx->canvas_height; 40 | int iw = cairo_image_surface_get_width (image); 41 | int ih = cairo_image_surface_get_height (image); 42 | int pw = w - iw; 43 | int ph = h - ih; 44 | 45 | 46 | for (int i=0; isize; i++) { 47 | double x = (double)rnd()/RAND_MAX * pw; 48 | double y = (double)rnd()/RAND_MAX * ph; 49 | 50 | cairo_new_path(cr); 51 | cairo_save(cr); 52 | cairo_translate(cr, w/2, h/2); 53 | 54 | radian = (1/57.29) * (counter/50); 55 | cairo_rotate(cr, radian); 56 | 57 | cairo_translate(cr, -iw/2, -ih/2); 58 | cairo_set_source_surface (cr, cached_image, 0, 0); 59 | cairo_paint (cr); 60 | counter++; 61 | 62 | cairo_restore(cr); 63 | } 64 | 65 | 66 | return 1; 67 | } 68 | 69 | /* 70 | Local Variables: 71 | mode:c++ 72 | c-file-style:"stroustrup" 73 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 74 | indent-tabs-mode:nil 75 | fill-column:99 76 | End: 77 | */ 78 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 79 | -------------------------------------------------------------------------------- /src/cairo-tests/image-scale.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | #include 17 | 18 | static cairo_surface_t *image; 19 | static cairo_surface_t *cached_image; 20 | 21 | int 22 | ca_setup_image_scale(caskbench_context_t *ctx) 23 | { 24 | image = cairoCreateSampleImage (ctx); 25 | cached_image = cairoCacheImageSurface (ctx, image); 26 | return 1; 27 | } 28 | 29 | void 30 | ca_teardown_image_scale(void) 31 | { 32 | cairo_surface_destroy (image); 33 | cairo_surface_destroy (cached_image); 34 | } 35 | 36 | int 37 | ca_test_image_scale(caskbench_context_t *ctx) 38 | { 39 | cairo_t *cr = ctx->cairo_cr; 40 | 41 | int w = ctx->canvas_width; 42 | int h = ctx->canvas_height; 43 | int iw = cairo_image_surface_get_width (image); 44 | int ih = cairo_image_surface_get_height (image); 45 | for (int i=0; isize; i++) { 46 | double x1 = (double)rnd()/RAND_MAX * w; 47 | double x2 = (double)rnd()/RAND_MAX * w; 48 | double y1 = (double)rnd()/RAND_MAX * h; 49 | double y2 = (double)rnd()/RAND_MAX * h; 50 | double x = MIN(x1, x2); 51 | double y = MIN(y1, y2); 52 | double width_ratio = float(fabs(x2 - x1)) / float(iw); 53 | double height_ratio = float(fabs(y2 - y1)) / float(ih); 54 | 55 | cairo_save(cr); 56 | cairo_translate(cr,x,y); 57 | cairo_scale(cr, width_ratio, height_ratio); 58 | 59 | cairo_set_source_surface (cr, cached_image, 0, 0); 60 | // Scale without blur 61 | cairo_pattern_set_filter (cairo_get_source(cr), CAIRO_FILTER_FAST); 62 | #if 1 63 | // Paint method 64 | cairo_paint (cr); 65 | #else 66 | // Fill Method 67 | cairo_rectangle(cr, 0, 0, iw, ih); 68 | cairo_fill(cr); 69 | #endif 70 | cairo_restore(cr); 71 | } 72 | return 1; 73 | } 74 | 75 | /* 76 | Local Variables: 77 | mode:c++ 78 | c-file-style:"stroustrup" 79 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 80 | indent-tabs-mode:nil 81 | fill-column:99 82 | End: 83 | */ 84 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 85 | -------------------------------------------------------------------------------- /src/cairo-tests/image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include 16 | 17 | static cairo_surface_t *image; 18 | static cairo_surface_t *cached_image; 19 | 20 | int 21 | ca_setup_image(caskbench_context_t *ctx) 22 | { 23 | image = cairoCreateSampleImage (ctx); 24 | cached_image = cairoCacheImageSurface (ctx, image); 25 | return 1; 26 | } 27 | 28 | void 29 | ca_teardown_image(void) 30 | { 31 | cairo_surface_destroy (image); 32 | cairo_surface_destroy (cached_image); 33 | } 34 | 35 | int 36 | ca_test_image(caskbench_context_t* ctx) 37 | { 38 | cairo_t *cr = ctx->cairo_cr; 39 | 40 | int w = ctx->canvas_width; 41 | int h = ctx->canvas_height; 42 | int iw = cairo_image_surface_get_width (image); 43 | int ih = cairo_image_surface_get_height (image); 44 | int pw = w - iw; 45 | int ph = h - ih; 46 | 47 | for (int i=0; isize; i++) { 48 | double x = (double)rnd()/RAND_MAX * pw; 49 | double y = (double)rnd()/RAND_MAX * ph; 50 | cairo_set_source_surface (cr, cached_image, x, y); 51 | #if 1 52 | cairo_paint (cr); 53 | #else 54 | // Fill Method 55 | cairo_rectangle(cr, x, y, iw, ih); 56 | cairo_fill(cr); 57 | #endif 58 | 59 | } 60 | return 1; 61 | } 62 | 63 | /* 64 | Local Variables: 65 | mode:c++ 66 | c-file-style:"stroustrup" 67 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 68 | indent-tabs-mode:nil 69 | fill-column:99 70 | End: 71 | */ 72 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 73 | -------------------------------------------------------------------------------- /src/cairo-tests/line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_line(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_line(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_line(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | double x1 = (double)rnd()/RAND_MAX * w; 40 | double x2 = (double)rnd()/RAND_MAX * w; 41 | double y1 = (double)rnd()/RAND_MAX * h; 42 | double y2 = (double)rnd()/RAND_MAX * h; 43 | 44 | shape.x = x1; 45 | shape.y = y1; 46 | shape.width = x1 - x2; 47 | shape.height = y1 - y2; 48 | 49 | cairoRandomizeColor(ctx); 50 | cairoDrawLine(ctx, &shape); 51 | cairo_stroke(ctx->cairo_cr); 52 | } 53 | 54 | return 1; 55 | } 56 | 57 | /* 58 | Local Variables: 59 | mode:c++ 60 | c-file-style:"stroustrup" 61 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 62 | indent-tabs-mode:nil 63 | fill-column:99 64 | End: 65 | */ 66 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 67 | -------------------------------------------------------------------------------- /src/cairo-tests/linear-gradient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "caskbench.h" 13 | #include "caskbench_context.h" 14 | #include "cairo-shapes.h" 15 | #include 16 | 17 | int 18 | ca_setup_linear_gradient(caskbench_context_t *ctx) 19 | { 20 | return 1; 21 | } 22 | 23 | void 24 | ca_teardown_linear_gradient(void) 25 | { 26 | } 27 | 28 | int 29 | ca_test_linear_gradient(caskbench_context_t *ctx) 30 | { 31 | int w = ctx->canvas_width; 32 | int h = ctx->canvas_height; 33 | 34 | int stops = 2; 35 | double x1,y1 ,x2,y2; 36 | x1 = y1 = 0; 37 | x2 = y2 = 100; 38 | 39 | cairo_t *cr = ctx->cairo_cr; 40 | cairo_pattern_t *pattern = cairo_pattern_create_linear (0,0,100,100); 41 | 42 | for (int i = 1; i <= stops; i++) { 43 | double red, green, blue, alpha; 44 | generate_random_color(red,green,blue,alpha); 45 | cairo_pattern_add_color_stop_rgba (pattern, i/(stops), red, green, blue, alpha); 46 | } 47 | 48 | shapes_t shape; 49 | shape_copy(&ctx->shape_defaults, &shape); 50 | for (int i=0; isize; i++) { 51 | double x1 = (double)rnd()/RAND_MAX * w; 52 | double x2 = (double)rnd()/RAND_MAX * w; 53 | double y1 = (double)rnd()/RAND_MAX * h; 54 | double y2 = (double)rnd()/RAND_MAX * h; 55 | double x = MIN(x1, x2); 56 | double y = MIN(y1, y2); 57 | 58 | double width_ratio = float(fabs(x2 - x1)) / float(100); 59 | double height_ratio = float(fabs(y2 - y1)) / float(100); 60 | 61 | cairo_save(cr); 62 | cairo_translate(cr, x, y); 63 | 64 | cairo_scale(cr, width_ratio, height_ratio); 65 | // transform(shape.width/100, 0, 0, shape.height/100, 0, 0) 66 | shape.x = 0; 67 | shape.y = 0; 68 | shape.width = 100; 69 | shape.height = 100; 70 | shape.fill_type = CB_FILL_LINEAR_GRADIENT; 71 | 72 | cairo_set_source (cr, pattern); 73 | cairoDrawRectangle(ctx, &shape); 74 | 75 | cairo_fill (cr); 76 | cairo_restore(cr); 77 | } 78 | cairo_pattern_destroy(pattern); 79 | return 1; 80 | } 81 | 82 | /* 83 | Local Variables: 84 | mode:c++ 85 | c-file-style:"stroustrup" 86 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 87 | indent-tabs-mode:nil 88 | fill-column:99 89 | End: 90 | */ 91 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 92 | -------------------------------------------------------------------------------- /src/cairo-tests/mask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #if USE_EGL 13 | # include 14 | #endif 15 | 16 | #include "caskbench.h" 17 | #include "caskbench_context.h" 18 | #include "cairo-shapes.h" 19 | 20 | static cairo_pattern_t *mask; 21 | 22 | int 23 | ca_setup_mask(caskbench_context_t *ctx) 24 | { 25 | // See https://git.gnome.org/browse/gtk+/tree/gtk/gtkcolorbutton.c?id=804c80097995bb0026544118a32b59e23ee2fbe3#n241 26 | static unsigned char data[16] = { 0xFF, 0x00, 0x00, 0xFF, 27 | 0x00, 0xFF, 0xFF, 0x00, 28 | 0x00, 0xFF, 0xFF, 0x00, 29 | 0xFF, 0x00, 0x00, 0xFF, }; 30 | cairo_surface_t *stippled = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_A8, 2, 2, 4); 31 | #if USE_EGL 32 | if (cairo_surface_get_type (ctx->cairo_surface) == CAIRO_SURFACE_TYPE_GL) { 33 | cairo_surface_t *cairo_surface; 34 | cairo_device_t *cairo_device = cairo_surface_get_device (ctx->cairo_surface); 35 | 36 | /* create a gl surface similar to image surface */ 37 | cairo_surface = cairo_gl_surface_create (cairo_device, CAIRO_CONTENT_COLOR_ALPHA, 2, 2); 38 | cairo_t *gl_ctx = cairo_create (cairo_surface); 39 | cairo_pattern_t *pattern = cairo_pattern_create_for_surface (stippled); 40 | cairo_set_source (gl_ctx, pattern); 41 | 42 | /* paint image surface to gl surface as a pattern */ 43 | cairo_paint (gl_ctx); 44 | cairo_destroy (gl_ctx); 45 | 46 | /* use gl surface as mask */ 47 | mask = cairo_pattern_create_for_surface (cairo_surface); 48 | } 49 | else 50 | #endif 51 | mask = cairo_pattern_create_for_surface (stippled); 52 | cairo_pattern_set_extend (mask, CAIRO_EXTEND_REPEAT); 53 | cairo_pattern_set_filter (mask, CAIRO_FILTER_NEAREST); 54 | 55 | return 1; 56 | } 57 | 58 | void 59 | ca_teardown_mask(void) 60 | { 61 | cairo_pattern_destroy (mask); 62 | } 63 | 64 | int 65 | ca_test_mask(caskbench_context_t *ctx) 66 | { 67 | int i; 68 | cairo_t *cr = ctx->cairo_cr; 69 | 70 | for (i=0; isize; i++) { 71 | // Apply mask on a circle 72 | cairoRandomizeColor(ctx); 73 | 74 | cairo_arc (cr, 40*i, 40, 30, 0, 2*M_PI); 75 | cairo_save (cr); 76 | cairo_clip (cr); 77 | cairo_mask (cr, mask); 78 | cairo_fill (cr); 79 | cairo_restore (cr); 80 | } 81 | return 1; 82 | } 83 | 84 | /* 85 | Local Variables: 86 | mode:c++ 87 | c-file-style:"stroustrup" 88 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 89 | indent-tabs-mode:nil 90 | fill-column:99 91 | End: 92 | */ 93 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 94 | -------------------------------------------------------------------------------- /src/cairo-tests/multi-line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_multi_line(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_multi_line(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_multi_line(caskbench_context_t *ctx) 32 | { 33 | 34 | int w = ctx->canvas_width; 35 | int h = ctx->canvas_height; 36 | double x = (double)rnd()/RAND_MAX * w; 37 | double y = (double)rnd()/RAND_MAX * h; 38 | 39 | cairo_move_to (ctx->cairo_cr,x, y); 40 | for (int i=0; isize; i++) { 41 | x = (double)rnd()/RAND_MAX * w; 42 | y = (double)rnd()/RAND_MAX * h; 43 | 44 | cairo_line_to (ctx->cairo_cr,x, y); 45 | } 46 | cairoRandomizeColor(ctx); 47 | cairo_close_path(ctx->cairo_cr); 48 | cairo_stroke(ctx->cairo_cr); 49 | 50 | return 1; 51 | } 52 | 53 | /* 54 | Local Variables: 55 | mode:c++ 56 | c-file-style:"stroustrup" 57 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 58 | indent-tabs-mode:nil 59 | fill-column:99 60 | End: 61 | */ 62 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 63 | -------------------------------------------------------------------------------- /src/cairo-tests/multi-shape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | 18 | static int element_spacing; 19 | static int num_x_elements; 20 | static int num_y_elements; 21 | 22 | int 23 | ca_setup_multi_shape(caskbench_context_t *ctx) 24 | { 25 | if (ctx->size < 0) 26 | return 0; 27 | 28 | // Multi-shape setup 29 | element_spacing = sqrt( ((double)ctx->canvas_width * ctx->canvas_height) / ctx->size); 30 | num_x_elements = ctx->canvas_width / element_spacing; 31 | num_y_elements = ctx->canvas_height / element_spacing; 32 | 33 | return 1; 34 | } 35 | 36 | void 37 | ca_teardown_multi_shape(void) 38 | { 39 | } 40 | 41 | int 42 | ca_test_multi_shape(caskbench_context_t *ctx) 43 | { 44 | ctx->shape_defaults.radius = 0.9 * element_spacing / 2; 45 | ctx->shape_defaults.width = 2*ctx->shape_defaults.radius; 46 | ctx->shape_defaults.height = 2*ctx->shape_defaults.radius; 47 | 48 | for (int j=0; jshape_defaults, &shape); 52 | shape.x = i * element_spacing; 53 | shape.y = j * element_spacing; 54 | 55 | cairoDrawRandomizedShape(ctx, &shape); 56 | } 57 | } 58 | 59 | return 1; 60 | } 61 | 62 | /* 63 | Local Variables: 64 | mode:c++ 65 | c-file-style:"stroustrup" 66 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 67 | indent-tabs-mode:nil 68 | fill-column:99 69 | End: 70 | */ 71 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 72 | -------------------------------------------------------------------------------- /src/cairo-tests/paint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_paint(caskbench_context_t *ctx) 19 | { 20 | return 1; 21 | } 22 | 23 | void 24 | ca_teardown_paint() 25 | { 26 | } 27 | 28 | int 29 | ca_test_paint(caskbench_context_t *ctx) 30 | { 31 | int i; 32 | 33 | for (i=0; isize; i++) { 34 | cairoRandomizeColor(ctx); 35 | cairo_paint(ctx->cairo_cr); 36 | } 37 | return 1; 38 | } 39 | 40 | /* 41 | Local Variables: 42 | mode:c++ 43 | c-file-style:"stroustrup" 44 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 45 | indent-tabs-mode:nil 46 | fill-column:99 47 | End: 48 | */ 49 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 50 | -------------------------------------------------------------------------------- /src/cairo-tests/quadratic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_quadratic(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_quadratic(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_quadratic(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | shape.x = (double)rnd()/RAND_MAX * w; 40 | shape.dx1 = (double)rnd()/RAND_MAX * w; 41 | shape.width = (double)rnd()/RAND_MAX * w - shape.x; 42 | shape.y = (double)rnd()/RAND_MAX * h; 43 | shape.dy1 = (double)rnd()/RAND_MAX * h; 44 | shape.height = (double)rnd()/RAND_MAX * h - shape.y; 45 | 46 | cairoRandomizeColor(ctx); 47 | cairoDrawQuadraticCurve(ctx, &shape); 48 | cairo_stroke(ctx->cairo_cr); 49 | } 50 | 51 | return 1; 52 | } 53 | 54 | /* 55 | Local Variables: 56 | mode:c++ 57 | c-file-style:"stroustrup" 58 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 59 | indent-tabs-mode:nil 60 | fill-column:99 61 | End: 62 | */ 63 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 64 | -------------------------------------------------------------------------------- /src/cairo-tests/radial-gradient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "caskbench.h" 13 | #include "caskbench_context.h" 14 | #include "cairo-shapes.h" 15 | #include 16 | 17 | int 18 | ca_setup_radial_gradient(caskbench_context_t *ctx) 19 | { 20 | return 1; 21 | } 22 | 23 | void 24 | ca_teardown_radial_gradient(void) 25 | { 26 | } 27 | 28 | int 29 | ca_test_radial_gradient(caskbench_context_t *ctx) 30 | { 31 | int w = ctx->canvas_width; 32 | int h = ctx->canvas_height; 33 | 34 | int stops = 2; 35 | cairo_pattern_t *pattern = cairo_pattern_create_radial (20,20,20,50,50,70); 36 | 37 | for (int i = 0; i < stops; i++) { 38 | double red, green, blue, alpha; 39 | generate_random_color(red,green,blue,alpha); 40 | cairo_pattern_add_color_stop_rgba (pattern, i/(stops-1), red, green, blue, alpha); 41 | } 42 | 43 | cairo_t *cr = ctx->cairo_cr; 44 | 45 | shapes_t shape; 46 | shape_copy(&ctx->shape_defaults, &shape); 47 | for (int i=0; isize; i++) { 48 | double x1 = (double)rnd()/RAND_MAX * w; 49 | double x2 = (double)rnd()/RAND_MAX * w; 50 | double y1 = (double)rnd()/RAND_MAX * h; 51 | double y2 = (double)rnd()/RAND_MAX * h; 52 | double x = MIN(x1, x2); 53 | double y = MIN(y1, y2); 54 | 55 | double width_ratio = float(fabs(x2 - x1)) / float(100); 56 | double height_ratio = float(fabs(y2 - y1)) / float(100); 57 | 58 | cairo_save(cr); 59 | cairo_translate(cr,x, y); 60 | 61 | cairo_scale(cr, width_ratio, height_ratio); 62 | 63 | shape.x = 0; 64 | shape.y = 0; 65 | shape.width = 100; 66 | shape.height = 100; 67 | shape.fill_type = CB_FILL_LINEAR_GRADIENT; 68 | 69 | cairo_set_source (cr, pattern); 70 | cairoDrawRectangle(ctx, &shape); 71 | 72 | cairo_fill (cr); 73 | cairo_restore(cr); 74 | } 75 | cairo_pattern_destroy(pattern); 76 | 77 | return 1; 78 | } 79 | 80 | /* 81 | Local Variables: 82 | mode:c++ 83 | c-file-style:"stroustrup" 84 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 85 | indent-tabs-mode:nil 86 | fill-column:99 87 | End: 88 | */ 89 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 90 | -------------------------------------------------------------------------------- /src/cairo-tests/rect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_rect(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_rect(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_rect(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | double x1 = (double)rnd()/RAND_MAX * w; 40 | double x2 = (double)rnd()/RAND_MAX * w; 41 | double y1 = (double)rnd()/RAND_MAX * h; 42 | double y2 = (double)rnd()/RAND_MAX * h; 43 | 44 | shape.x = MIN(x1, x2); 45 | shape.y = MIN(x1, x2); 46 | shape.width = abs(x2 - x1); 47 | shape.height = abs(y2 - y1); 48 | 49 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 50 | shape.fill_type = generate_random_fill_type(); 51 | } 52 | ca_set_fill_style(ctx, &shape); 53 | 54 | shape.shape_type = CB_SHAPE_RECTANGLE; 55 | cairoDrawRandomizedShape(ctx,&shape); 56 | } 57 | 58 | return 1; 59 | } 60 | 61 | /* 62 | Local Variables: 63 | mode:c++ 64 | c-file-style:"stroustrup" 65 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 66 | indent-tabs-mode:nil 67 | fill-column:99 68 | End: 69 | */ 70 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 71 | -------------------------------------------------------------------------------- /src/cairo-tests/rectangles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | 18 | int 19 | ca_setup_rectangles(caskbench_context_t *ctx) 20 | { 21 | cairo_t *cr = ctx->cairo_cr; 22 | 23 | cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT); 24 | cairo_set_line_width (cr, 1); 25 | return 1; 26 | } 27 | 28 | void 29 | ca_teardown_rectangles(void) 30 | { 31 | } 32 | 33 | int 34 | ca_test_rectangles(caskbench_context_t *ctx) 35 | { 36 | int i; 37 | double w, h, x, y; 38 | cairo_t *cr = ctx->cairo_cr; 39 | 40 | for (i=0; isize; i++) { 41 | cairoRandomizeColor(ctx); 42 | 43 | w = trunc( (0.5*(double)ctx->canvas_width*rnd())/RAND_MAX ) + 1; 44 | h = trunc( (0.5*(double)ctx->canvas_height*rnd())/RAND_MAX ) + 1; 45 | x = trunc( (0.5*(double)ctx->canvas_width*rnd())/RAND_MAX ); 46 | y = trunc( (0.5*(double)ctx->canvas_height*rnd())/RAND_MAX ); 47 | cairo_rectangle(cr, x+1, y+1, w, h); 48 | 49 | cairo_stroke (cr); 50 | } 51 | return 1; 52 | } 53 | 54 | /* 55 | Local Variables: 56 | mode:c++ 57 | c-file-style:"stroustrup" 58 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 59 | indent-tabs-mode:nil 60 | fill-column:99 61 | End: 62 | */ 63 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 64 | -------------------------------------------------------------------------------- /src/cairo-tests/roundrect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | 18 | int 19 | ca_setup_roundrect(caskbench_context_t *ctx) 20 | { 21 | cairo_t *cr = ctx->cairo_cr; 22 | 23 | cairo_set_antialias (cr, CAIRO_ANTIALIAS_BEST); 24 | return 1; 25 | } 26 | 27 | void 28 | ca_teardown_roundrect(void) 29 | { 30 | } 31 | 32 | static void 33 | rounded_rectangle (cairo_t *cr, 34 | double x, double y, double w, double h, 35 | double radius) 36 | { 37 | cairo_move_to (cr, x+radius, y); 38 | cairo_arc (cr, x+w-radius, y+radius, radius, M_PI + M_PI / 2, M_PI * 2 ); 39 | cairo_arc (cr, x+w-radius, y+h-radius, radius, 0, M_PI / 2 ); 40 | cairo_arc (cr, x+radius, y+h-radius, radius, M_PI/2, M_PI ); 41 | cairo_arc (cr, x+radius, y+radius, radius, M_PI, 270 * M_PI / 180); 42 | } 43 | 44 | int 45 | ca_test_roundrect(caskbench_context_t *ctx) 46 | { 47 | int i; 48 | double line_width, x, y, radius; 49 | cairo_t *cr = ctx->cairo_cr; 50 | 51 | for (i=0; isize; i++) { 52 | shapes_t shape; 53 | shape_copy(&ctx->shape_defaults, &shape); 54 | 55 | cairoRandomizeColor(ctx); 56 | 57 | shape.x = 10 + trunc( (((double)ctx->canvas_width-20.0)*rnd())/RAND_MAX ); 58 | shape.y = 10 + trunc( (((double)ctx->canvas_height-20.0)*rnd())/RAND_MAX ); 59 | 60 | /* vary radius upto half of MIN(X,Y) */ 61 | shape.radius = (double)rnd()/RAND_MAX * 20; 62 | shape.width = 100; 63 | shape.height = 40; 64 | 65 | /* line_width cannot be more than twice of radius due to skia limitation - Issue #4 in skia https://github.com/Samsung/skia/issues/4 */ 66 | shape.stroke_width = (double)rnd()/RAND_MAX * (2*shape.radius); 67 | 68 | cairoDrawRoundedRectangle(ctx, &shape); 69 | 70 | cairo_set_line_width (cr, shape.stroke_width); 71 | 72 | cairo_stroke (cr); 73 | } 74 | return 1; 75 | } 76 | 77 | /* 78 | Local Variables: 79 | mode:c++ 80 | c-file-style:"stroustrup" 81 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 82 | indent-tabs-mode:nil 83 | fill-column:99 84 | End: 85 | */ 86 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 87 | -------------------------------------------------------------------------------- /src/cairo-tests/star.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_star(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_star(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_star(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | int counter = 1; // TODO 36 | 37 | shapes_t shape; 38 | shape_copy(&ctx->shape_defaults, &shape); 39 | for (int j = 0; jcairo_cr); 43 | cairo_save(ctx->cairo_cr); 44 | cairo_translate(ctx->cairo_cr,i, j); 45 | //ctx->skia_canvas->rotate(counter / 2000.0); 46 | cairo_scale(ctx->cairo_cr,0.2, 0.2); 47 | shape.x = 0; 48 | shape.y = 0; 49 | shape.radius = 40; 50 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 51 | shape.fill_type = generate_random_fill_type(); 52 | } 53 | ca_set_fill_style(ctx, &shape); 54 | 55 | shape.shape_type = CB_SHAPE_STAR; 56 | cairoDrawRandomizedShape(ctx,&shape); 57 | cairo_restore(ctx->cairo_cr); 58 | } 59 | } 60 | 61 | return 1; 62 | } 63 | 64 | /* 65 | Local Variables: 66 | mode:c++ 67 | c-file-style:"stroustrup" 68 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 69 | indent-tabs-mode:nil 70 | fill-column:99 71 | End: 72 | */ 73 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 74 | -------------------------------------------------------------------------------- /src/cairo-tests/text-glyphs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | 18 | // This test converts a text string to glyphs and displays it at various font sizes 19 | 20 | static int max_dim; 21 | static char rand_text_array[19][100]; 22 | 23 | static void 24 | gen_random(char *s, const int len) { 25 | static const char alphanum[] = 26 | "ABCD EFG HIJKL MNOPQ RSTUVW XYZ"; 27 | 28 | for (int i = 0; i < len; ++i) { 29 | s[i] = alphanum[rnd() % (sizeof(alphanum) - 1)]; 30 | } 31 | 32 | s[len] = 0; 33 | } 34 | 35 | int 36 | ca_setup_text_glyphs(caskbench_context_t *ctx) 37 | { 38 | max_dim = MIN (ctx->canvas_width, ctx->canvas_height)/2; 39 | return 1; 40 | } 41 | 42 | void 43 | ca_teardown_text_glyphs(void) 44 | { 45 | } 46 | 47 | int 48 | ca_test_text_glyphs(caskbench_context_t *ctx) 49 | { 50 | cairo_t *cr = ctx->cairo_cr; 51 | double font_size = 18; 52 | int ypos = 15, xpos = 0; 53 | int num_glyphs = 0, num_clusters = 0; 54 | 55 | double font_factor = 0.5; 56 | 57 | cairo_set_source_rgb (cr, 0, 0, 0); 58 | cairo_rectangle (cr, 0, 0, ctx->canvas_width ,ctx->canvas_height); 59 | cairo_fill (cr); 60 | for (int i = 0; i < ctx->size; i++) 61 | { 62 | num_glyphs = 0; 63 | num_clusters = 0; 64 | cairo_set_font_size (cr, font_size); 65 | cairoRandomizeColor (ctx); 66 | 67 | cairo_status_t status; 68 | cairo_scaled_font_t *font; 69 | font = cairo_get_scaled_font (cr); 70 | cairo_glyph_t *glyphs = NULL; 71 | cairo_text_cluster_t *clusters = NULL; 72 | cairo_text_cluster_flags_t cluster_flags; 73 | 74 | char text[(int)font_size]; 75 | gen_random (text,font_size); 76 | 77 | status = cairo_scaled_font_text_to_glyphs (font, 78 | xpos, ypos, 79 | text, font_size, 80 | &glyphs, &num_glyphs, 81 | &clusters, &num_clusters, &cluster_flags); 82 | 83 | if (status == CAIRO_STATUS_SUCCESS) { 84 | cairo_show_text_glyphs (cr, 85 | text,font_size, 86 | glyphs, num_glyphs, 87 | clusters, num_clusters, cluster_flags); 88 | } 89 | 90 | font_size = font_size+font_factor; 91 | ypos += (font_size/2); 92 | if (font_size >= 36) 93 | font_size = 36; 94 | if (ypos > ctx->canvas_height/2) 95 | font_factor = -0.5; 96 | if (font_size < 18) 97 | font_size = 18; 98 | } 99 | return 1; 100 | } 101 | 102 | /* 103 | Local Variables: 104 | mode:c++ 105 | c-file-style:"stroustrup" 106 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 107 | indent-tabs-mode:nil 108 | fill-column:99 109 | End: 110 | */ 111 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 112 | -------------------------------------------------------------------------------- /src/cairo-tests/text.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "cairo-shapes.h" 17 | 18 | // This tests basic (non-glyph) text functionality 19 | 20 | int 21 | ca_setup_text(caskbench_context_t *ctx) 22 | { 23 | cairo_t *cr = ctx->cairo_cr; 24 | cairo_select_font_face(cr, "Serif", 25 | CAIRO_FONT_SLANT_NORMAL, 26 | CAIRO_FONT_WEIGHT_BOLD); 27 | 28 | cairo_set_font_size(cr, 20); 29 | cairo_set_antialias(cr,CAIRO_ANTIALIAS_NONE); 30 | return 1; 31 | } 32 | 33 | void 34 | ca_teardown_text(void) 35 | { 36 | } 37 | 38 | int 39 | ca_test_text(caskbench_context_t *ctx) 40 | { 41 | char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 42 | cairo_t *cr = ctx->cairo_cr; 43 | size_t byteLength = strlen(text) * sizeof(char); 44 | cairo_text_extents_t text_metrics; 45 | cairo_text_extents (cr, text, &text_metrics); 46 | double tw = text_metrics.width + 3; // Adding 3 to make tw value same as skia text. 47 | double w = (double) ctx->canvas_width; 48 | double h = (double) ctx->canvas_height; 49 | double off = abs (w - tw); 50 | 51 | cairo_set_source_rgb (cr, 0, 0, 0); 52 | cairo_rectangle (cr, 0, 0, ctx->canvas_width ,ctx->canvas_height); 53 | cairo_fill (cr); 54 | 55 | for (int i = 0; i < ctx->size; i++) 56 | { 57 | double x = drnd48() * off; 58 | double y = drnd48() * h; 59 | 60 | cairoRandomizeColor(ctx); 61 | cairo_move_to(cr, x, y); 62 | cairo_show_text(cr, text); 63 | } 64 | return 1; 65 | } 66 | 67 | /* 68 | Local Variables: 69 | mode:c++ 70 | c-file-style:"stroustrup" 71 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 72 | indent-tabs-mode:nil 73 | fill-column:99 74 | End: 75 | */ 76 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 77 | -------------------------------------------------------------------------------- /src/cairo-tests/transform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_transform(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_transform(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_transform(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | double rotation_delta(0.02*180/M_PI); 36 | cairo_t *cr = ctx->cairo_cr; 37 | 38 | cairo_save (cr); 39 | for (int nn=0; nnsize; nn++) { 40 | for (int i=0; i 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "cairo-shapes.h" 16 | 17 | int 18 | ca_setup_vline(caskbench_context_t *ctx) 19 | { 20 | cairo_set_antialias (ctx->cairo_cr, CAIRO_ANTIALIAS_NONE); 21 | cairo_set_line_width (ctx->cairo_cr, 1); 22 | return 1; 23 | } 24 | 25 | void 26 | ca_teardown_vline(void) 27 | { 28 | } 29 | 30 | int 31 | ca_test_vline(caskbench_context_t *ctx) 32 | { 33 | int w = ctx->canvas_width; 34 | int h = ctx->canvas_height; 35 | 36 | shapes_t shape; 37 | shape_copy(&ctx->shape_defaults, &shape); 38 | for (int i=0; isize; i++) { 39 | 40 | double x = (double)rnd()/RAND_MAX * w; 41 | double y1 = (double)rnd()/RAND_MAX * h; 42 | double y2 = (double)rnd()/RAND_MAX * h; 43 | 44 | shape.x = x; 45 | shape.y = y1; 46 | shape.width = 0; 47 | shape.height = y1 - y2; 48 | 49 | cairoRandomizeColor(ctx); 50 | cairoDrawLine(ctx, &shape); 51 | cairo_stroke(ctx->cairo_cr); 52 | } 53 | 54 | return 1; 55 | } 56 | 57 | /* 58 | Local Variables: 59 | mode:c++ 60 | c-file-style:"stroustrup" 61 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 62 | indent-tabs-mode:nil 63 | fill-column:99 64 | End: 65 | */ 66 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 67 | -------------------------------------------------------------------------------- /src/cairo-util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "forward.h" 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | 17 | void 18 | context_clear_cairo(caskbench_context_t *context) 19 | { 20 | cairo_set_source_rgb (context->cairo_cr, 0, 0, 0); 21 | cairo_paint (context->cairo_cr); 22 | } 23 | 24 | void 25 | write_image_file_cairo (const char *fname, caskbench_context_t *context) 26 | { 27 | assert (context->cairo_surface); 28 | cairo_status_t status = cairo_surface_status (context->cairo_surface); 29 | if (status != CAIRO_STATUS_SUCCESS) { 30 | warnx("Error writing cairo surface to file: %s\n", cairo_status_to_string(status)); 31 | return; 32 | } 33 | cairo_surface_write_to_png (context->cairo_surface, fname); 34 | } 35 | 36 | /* 37 | Local Variables: 38 | mode:c++ 39 | c-file-style:"stroustrup" 40 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 41 | indent-tabs-mode:nil 42 | fill-column:99 43 | End: 44 | */ 45 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 46 | -------------------------------------------------------------------------------- /src/caskbench.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __CASKBENCH_H__ // -*- mode: c++ -*- 8 | #define __CASKBENCH_H__ 9 | 10 | #ifndef M_PI 11 | # define M_PI 3.14159265358979323846 12 | #endif 13 | 14 | #ifndef MIN 15 | # define MIN(a,b) (((a) < (b)) ? (a) : (b)) 16 | #endif 17 | 18 | #ifndef MAX 19 | # define MAX(a,b) (((a) > (b)) ? (a) : (b)) 20 | #endif 21 | 22 | #ifndef NUM_ELEM 23 | # define NUM_ELEM(x) (sizeof(x)/sizeof(x[0])) 24 | #endif 25 | 26 | #ifndef MAX_BUFFER 27 | # define MAX_BUFFER 256 28 | #endif 29 | 30 | // Framework 31 | double get_tick (void); 32 | void display_results_json(int iterations, int status); 33 | 34 | #endif // __CASKBENCH_H__ 35 | /* 36 | Local Variables: 37 | mode:c++ 38 | c-file-style:"stroustrup" 39 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 40 | indent-tabs-mode:nil 41 | fill-column:99 42 | End: 43 | */ 44 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 45 | -------------------------------------------------------------------------------- /src/caskbench_context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __CASKBENCH_CONTEXT_H__ // -*- mode: c++ -*- 8 | #define __CASKBENCH_CONTEXT_H__ 9 | 10 | #include "shapes.h" 11 | #include "forward.h" 12 | 13 | typedef struct _caskbench_context { 14 | int size; 15 | int canvas_width; 16 | int canvas_height; 17 | 18 | cairo_t *cairo_cr; 19 | cairo_surface_t *cairo_surface; 20 | 21 | SkPaint *skia_paint; 22 | SkCanvas *skia_canvas; // Acts as SkDeferredCanvas only when deferred-rendering is enabled. 23 | SkCanvas *skia_canvas_immediate; // Backup for Immediate/Regular Skia canvas. 24 | SkBaseDevice *skia_device; 25 | SkSurface *dSurface; 26 | SkImage *snapshot; 27 | 28 | cairo_surface_t *(*setup_cairo)(const device_config_t& config); 29 | SkBaseDevice *(*setup_skia)(const device_config_t& config); 30 | void (*destroy_cairo)(void); 31 | void (*destroy_skia)(void); 32 | void (*update_cairo)(void); 33 | void (*update_skia)(void); 34 | 35 | const char *stock_image_path; 36 | shapes_t shape_defaults; 37 | double tolerance; 38 | int is_egl_deferred; 39 | 40 | } caskbench_context_t; 41 | 42 | // Backend-specific graphics initialization 43 | cairo_surface_t * create_cairo_surface_image (const device_config_t& config); 44 | void destroy_cairo_image(); 45 | void update_cairo_image(); 46 | 47 | SkBaseDevice * create_skia_device_image (const device_config_t& config); 48 | void destroy_skia_image(); 49 | void update_skia_image(); 50 | 51 | #if USE_GLX 52 | cairo_surface_t *create_cairo_surface_glx (const device_config_t& config); 53 | void destroy_cairo_glx(); 54 | void update_cairo_glx(); 55 | 56 | SkBaseDevice * create_skia_device_glx (const device_config_t& config); 57 | void destroy_skia_glx(); 58 | void update_skia_glx(); 59 | #endif 60 | 61 | #if USE_EGL 62 | cairo_surface_t * create_cairo_surface_egl (const device_config_t& config); 63 | void destroy_cairo_egl(); 64 | void update_cairo_egl(); 65 | 66 | SkBaseDevice * create_skia_device_egl (const device_config_t& config); 67 | void destroy_skia_egl(); 68 | void update_skia_egl(); 69 | #endif 70 | 71 | 72 | // Context initialization and management 73 | void context_init(caskbench_context_t *context, int size); 74 | void context_setup_cairo(caskbench_context_t *context, const device_config_t& config); 75 | void context_update_cairo(caskbench_context_t *context); 76 | void context_destroy_cairo(caskbench_context_t *context); 77 | void context_setup_skia(caskbench_context_t *context, const device_config_t& config); 78 | void context_update_skia(caskbench_context_t *context); 79 | void context_destroy_skia(caskbench_context_t *context); 80 | #endif // __CASKBENCH_CONTEXT_H__ 81 | 82 | /* 83 | Local Variables: 84 | mode:c++ 85 | c-file-style:"stroustrup" 86 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 87 | indent-tabs-mode:nil 88 | fill-column:99 89 | End: 90 | */ 91 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 92 | 93 | -------------------------------------------------------------------------------- /src/caskbench_result.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include "caskbench_result.h" 12 | 13 | void 14 | result_init(caskbench_result_t *result, const char* name) 15 | { 16 | assert(result); 17 | 18 | result->test_case_name = name; 19 | result->size = 0; 20 | result->min_run_time = -1.0; 21 | result->avg_run_time = -1.0; 22 | result->max_run_time = -1.0; 23 | result->median_run_time = -1.0; 24 | result->standard_deviation = -1.0; 25 | result->avg_frames_per_second = -1.0; 26 | result->status = 0; 27 | } 28 | 29 | /* 30 | Local Variables: 31 | mode:c++ 32 | c-file-style:"stroustrup" 33 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 34 | indent-tabs-mode:nil 35 | fill-column:99 36 | End: 37 | */ 38 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 39 | -------------------------------------------------------------------------------- /src/caskbench_result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __CASKBENCH_RESULT_H__ // -*- mode: c++ -*- 8 | #define __CASKBENCH_RESULT_H__ 9 | 10 | typedef struct _caskbench_result { 11 | const char *test_case_name; 12 | int size; 13 | int iterations; 14 | double min_run_time; 15 | double avg_run_time; 16 | double max_run_time; 17 | double median_run_time; 18 | double standard_deviation; 19 | double avg_frames_per_second; 20 | int status; 21 | } caskbench_result_t; 22 | 23 | void result_init(caskbench_result_t *result, const char* name); 24 | 25 | #endif // __CASKBENCH_RESULT_H__ 26 | 27 | /* 28 | Local Variables: 29 | mode:c++ 30 | c-file-style:"stroustrup" 31 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 32 | indent-tabs-mode:nil 33 | fill-column:99 34 | End: 35 | */ 36 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 37 | -------------------------------------------------------------------------------- /src/device_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __DEVICE_CONFIG_H__ // -*- mode: c++ -*- 8 | #define __DEVICE_CONFIG_H__ 9 | 10 | typedef struct _device_config { 11 | 12 | // General Settings 13 | const char *surface_type; 14 | int width; 15 | int height; 16 | 17 | // EGL Settings 18 | int egl_samples; 19 | int egl_sample_buffers; 20 | int egl_msaa_sample_count; 21 | int egl_gles_version; 22 | int egl_depth_size; 23 | int egl_luminance_size; 24 | int egl_min_swap_interval; 25 | int egl_max_swap_interval; 26 | int egl_match_native_pixmap; 27 | 28 | } device_config_t; 29 | 30 | #endif // __DEVICE_CONFIG_H__ 31 | /* 32 | Local Variables: 33 | mode:c++ 34 | c-file-style:"stroustrup" 35 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 36 | indent-tabs-mode:nil 37 | fill-column:99 38 | End: 39 | */ 40 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 41 | -------------------------------------------------------------------------------- /src/egl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __EGL_H__ // -*- mode: c++ -*- 8 | #define __EGL_H__ 9 | 10 | #include 11 | #include 12 | 13 | #include "forward.h" 14 | 15 | typedef struct { 16 | Display *dpy; 17 | Window window; 18 | 19 | EGLDisplay egl_display; 20 | EGLContext egl_context; 21 | EGLSurface egl_surface; 22 | } egl_state_t; 23 | 24 | bool createEGLContextAndWindow(egl_state_t *state, const device_config_t& device_config); 25 | void destroyEGLContextAndWindow(egl_state_t *state); 26 | void cleanup_state_egl(void *data); 27 | 28 | #endif // __EGL_H__ 29 | /* 30 | Local Variables: 31 | mode:c++ 32 | c-file-style:"stroustrup" 33 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 34 | indent-tabs-mode:nil 35 | fill-column:99 36 | End: 37 | */ 38 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 39 | -------------------------------------------------------------------------------- /src/forward.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __FORWARD_H__ // -*- mode: c++ -*- 8 | #define __FORWARD_H__ 9 | 10 | // Cairo forward declarations 11 | struct _cairo; 12 | typedef struct _cairo cairo_t; 13 | 14 | struct _cairo_surface; 15 | typedef struct _cairo_surface cairo_surface_t; 16 | 17 | 18 | // Skia forward declarations 19 | class SkPaint; 20 | class SkCanvas; 21 | class SkShader; 22 | class SkBaseDevice; 23 | class SkImage; 24 | class SkSurface; 25 | 26 | 27 | // Caskbench forward declarations 28 | struct _caskbench_context; 29 | typedef struct _caskbench_context caskbench_context_t; 30 | 31 | struct _device_config; 32 | typedef struct _device_config device_config_t; 33 | 34 | #endif 35 | /* 36 | Local Variables: 37 | mode:c++ 38 | c-file-style:"stroustrup" 39 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 40 | indent-tabs-mode:nil 41 | fill-column:99 42 | End: 43 | */ 44 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 45 | -------------------------------------------------------------------------------- /src/generate_git_info: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "x$1" = "x" ] || [ "x$2" = "x" ]; then 4 | echo "Usage: $0 " 5 | exit -1 6 | fi 7 | 8 | source_dir=$1 9 | out_file=$2 10 | git_command=$(git rev-parse HEAD) 11 | (cat < $out_file 16 | 17 | echo "" >> $out_file 18 | 19 | -------------------------------------------------------------------------------- /src/generate_tests: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "x$1" = "x" ] || [ "x$2" = "x" ]; then 4 | echo "Usage: $0 " 5 | exit -1 6 | fi 7 | 8 | source_dir=$1 9 | out_file=$2 10 | 11 | (cat < 13 | #include "tests.h" 14 | 15 | EOF 16 | ) > $out_file 17 | 18 | echo "" >> $out_file 19 | echo "#ifdef USE_CAIRO" >> $out_file 20 | echo "// Cairo Tests" >> $out_file 21 | for source_file in $(ls ${source_dir}/cairo-tests/*.cpp); do 22 | test=$(basename ${source_file%.cpp}) 23 | test=${test/-/_} 24 | (cat <> $out_file 31 | done 32 | echo "#endif // USE_CAIRO" >> $out_file 33 | 34 | echo "" >> $out_file 35 | echo "#ifdef USE_SKIA" >> $out_file 36 | echo "// Skia Tests" >> $out_file 37 | for source_file in $(ls ${source_dir}/skia-tests/*.cpp); do 38 | test=$(basename ${source_file%.cpp}) 39 | test=${test/-/_} 40 | (cat <> $out_file 47 | done 48 | echo "#endif // USE_SKIA" >> $out_file 49 | 50 | 51 | echo "" >> $out_file 52 | echo "caskbench_perf_test_t perf_tests[] = {" >> $out_file 53 | 54 | for source_file in $(ls ${source_dir}/cairo-tests/*.cpp); do 55 | original_test=$(basename ${source_file%.cpp}) 56 | test=${original_test/-/_} 57 | if [ ! -e ${source_dir}/skia-tests/${original_test}.cpp ]; then 58 | continue 59 | fi 60 | 61 | (cat <> $out_file 73 | 74 | done 75 | (cat <> $out_file 82 | 83 | -------------------------------------------------------------------------------- /src/git_info.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | 8 | #ifndef __GIT_INFO_H__ 9 | #define __GIT_INFO_H__ 10 | 11 | extern const char * git_sha; 12 | 13 | #endif //__GIT_INFO_H__ 14 | /* 15 | Local Variables: 16 | mode:c++ 17 | c-file-style:"stroustrup" 18 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 19 | indent-tabs-mode:nil 20 | fill-column:99 21 | End: 22 | */ 23 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 24 | -------------------------------------------------------------------------------- /src/glx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "glx.h" 13 | #include "device_config.h" 14 | 15 | bool 16 | createGLXContextAndWindow(glx_state_t *state, const device_config_t& device_config) 17 | { 18 | int rgba_attribs[] = { 19 | GLX_RGBA , 20 | GLX_RED_SIZE , 1, 21 | GLX_GREEN_SIZE , 1, 22 | GLX_BLUE_SIZE , 1, 23 | GLX_ALPHA_SIZE , 1, 24 | //GLX_STENCIL_SIZE , 8, 25 | //GLX_DOUBLEBUFFER , True, 26 | None 27 | }; 28 | XVisualInfo *visinfo; 29 | XSetWindowAttributes attrs; 30 | 31 | state->dpy = XOpenDisplay (NULL); 32 | if (!state->dpy) { 33 | warnx ("Failed to open display: %s\n", XDisplayName (0)); 34 | return false; 35 | } 36 | 37 | visinfo = glXChooseVisual (state->dpy, DefaultScreen (state->dpy), rgba_attribs); 38 | if (visinfo == NULL) { 39 | warnx ("Failed to create RGBA and double-buffered visuals\n"); 40 | XCloseDisplay (state->dpy); 41 | return NULL; 42 | } 43 | 44 | attrs.colormap = XCreateColormap (state->dpy, 45 | RootWindow (state->dpy, visinfo->screen), 46 | visinfo->visual, AllocNone); 47 | attrs.border_pixel = 0; 48 | state->window = XCreateWindow (state->dpy, DefaultRootWindow (state->dpy), 49 | 0, 0, 50 | device_config.width, device_config.height, 51 | 0, // border width 52 | visinfo->depth, 53 | InputOutput, visinfo->visual, 54 | CWBorderPixel | CWColormap | CWEventMask, 55 | &attrs); 56 | state->width = device_config.width; 57 | state->height = device_config.height; 58 | XMapWindow (state->dpy, state->window); 59 | 60 | //state->gc = XCreateGC(state->dpy, state->window, 0, NULL); 61 | 62 | state->glx_context = glXCreateContext (state->dpy, visinfo, NULL, True); 63 | XFree (visinfo); 64 | 65 | if (state->glx_context == NULL) { 66 | warnx ("Could not create glx context\n"); 67 | XCloseDisplay (state->dpy); 68 | return false; 69 | } 70 | 71 | return true; 72 | } 73 | 74 | void 75 | destroyGLXContextAndWindow (glx_state_t *state) 76 | { 77 | if (state->dpy) { 78 | if (state->glx_context) 79 | glXDestroyContext (state->dpy, state->glx_context); 80 | 81 | // XFreeGC (state->dpy, state->gc); 82 | XDestroyWindow (state->dpy, state->window); 83 | XCloseDisplay (state->dpy); 84 | } 85 | } 86 | 87 | void 88 | cleanup_state_glx (void *data) 89 | { 90 | glx_state_t *state = (glx_state_t*)data; 91 | destroyGLXContextAndWindow(state); 92 | free(state); 93 | } 94 | 95 | /* 96 | Local Variables: 97 | mode:c++ 98 | c-file-style:"stroustrup" 99 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 100 | indent-tabs-mode:nil 101 | fill-column:99 102 | End: 103 | */ 104 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 105 | -------------------------------------------------------------------------------- /src/glx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __GLX_H__ // -*- mode: c++ -*- 8 | #define __GLX_H__ 9 | 10 | #include 11 | #include 12 | 13 | 14 | typedef struct { 15 | Display *dpy; 16 | Window window; 17 | 18 | GLXContext glx_context; 19 | } glx_state_t; 20 | 21 | bool createGLXContextAndWindow(glx_state_t *state, int width, int height); 22 | void destroyGLXContextAndWindow(glx_state_t *state); 23 | void cleanup_state_glx(void *state); 24 | 25 | #endif // __GLX_H__ 26 | /* 27 | Local Variables: 28 | mode:c++ 29 | c-file-style:"stroustrup" 30 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 31 | indent-tabs-mode:nil 32 | fill-column:99 33 | End: 34 | */ 35 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 36 | -------------------------------------------------------------------------------- /src/image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "image.h" 13 | #include "device_config.h" 14 | 15 | void 16 | cleanup_state_image (void *data) 17 | { 18 | image_state_t *state = (image_state_t*)data; 19 | free(state); 20 | } 21 | 22 | bool 23 | createImageWindow(image_state_t *state, const device_config_t& device_config) 24 | { 25 | state->dpy = XOpenDisplay (NULL); 26 | if (!state->dpy) { 27 | warnx ("fail to open display: %s\n", XDisplayName (0)); 28 | return false; 29 | } 30 | 31 | int screen = DefaultScreen (state->dpy); 32 | 33 | XVisualInfo vi; 34 | XSetWindowAttributes attrs; 35 | 36 | XMatchVisualInfo (state->dpy, screen, 32, TrueColor, &vi); 37 | attrs.border_pixel = 0; 38 | attrs.event_mask = StructureNotifyMask; 39 | attrs.colormap = XCreateColormap (state->dpy, DefaultRootWindow (state->dpy), 40 | vi.visual, AllocNone); 41 | state->window = XCreateWindow (state->dpy, DefaultRootWindow (state->dpy), 42 | 0, 0, 43 | device_config.width, device_config.height, 44 | 0, 45 | vi.depth, 46 | InputOutput, vi.visual, 47 | CWBorderPixel | CWColormap | CWEventMask, 48 | &attrs); 49 | state->width = device_config.width; 50 | state->height = device_config.height; 51 | XMapWindow (state->dpy, state->window); 52 | 53 | state->gc = XCreateGC (state->dpy, state->window, 0, NULL); 54 | return true; 55 | } 56 | 57 | void 58 | updateImageWindow (image_state_t* state) 59 | { 60 | XPutImage (state->dpy, state->window, state->gc, &state->image, 61 | 0, 0, 62 | 0, 0, 63 | state->width, state->height); 64 | XSync (state->dpy, False); 65 | } 66 | 67 | void 68 | destroyImageWindow (image_state_t* state) 69 | { 70 | if (state->dpy) { 71 | XFreeGC (state->dpy, state->gc); 72 | XDestroyWindow (state->dpy, state->window); 73 | XCloseDisplay (state->dpy); 74 | } 75 | } 76 | 77 | /* 78 | Local Variables: 79 | mode:c++ 80 | c-file-style:"stroustrup" 81 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 82 | indent-tabs-mode:nil 83 | fill-column:99 84 | End: 85 | */ 86 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 87 | -------------------------------------------------------------------------------- /src/image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __IMAGE_H__ // -*- mode: c++ -*- 8 | #define __IMAGE_H__ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | typedef struct { 15 | Display *dpy; 16 | Window window; 17 | GC gc; 18 | XImage image; 19 | int width; 20 | int height; 21 | } image_state_t; 22 | 23 | void cleanup_state_image(void *data); 24 | bool createImageWindow(image_state_t *state, const device_config_t& device_config); 25 | void destroyImageWindow(image_state_t *state); 26 | void updateImageWindow(image_state_t *state); 27 | 28 | #endif // __IMAGE_H__ 29 | /* 30 | Local Variables: 31 | mode:c++ 32 | c-file-style:"stroustrup" 33 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 34 | indent-tabs-mode:nil 35 | fill-column:99 36 | End: 37 | */ 38 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 39 | -------------------------------------------------------------------------------- /src/kinetics.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | 15 | #include "kinetics.h" 16 | 17 | void 18 | kinetics_destroy (kinetics_t *kinetics) 19 | { 20 | free(kinetics); 21 | } 22 | 23 | void 24 | kinetics_init (kinetics_t *kinetics, const caskbench_context_t *ctx) 25 | { 26 | int max_velocity = ctx->canvas_width / 2; 27 | kinetics->angle = drnd48() * 2 * M_PI; 28 | kinetics->velocity = max_velocity / 8.0 * 7 * drnd48() + max_velocity / 8.0; 29 | kinetics->x = ctx->canvas_width / 2; 30 | kinetics->y = ctx->canvas_height / 2; 31 | 32 | kinetics->x_radius = drnd48() * 10 + 5; 33 | kinetics->y_radius = drnd48() * 10 + 5; 34 | kinetics->canvas_width = ctx->canvas_width; 35 | kinetics->canvas_height = ctx->canvas_height; 36 | kinetics->width = drnd48() * 120 + 30; 37 | kinetics->height = drnd48() * 120 + 30; 38 | 39 | kinetics->rotation = drnd48() * 2 * M_PI; 40 | kinetics->line_width = 20; //drnd48() * 20; 41 | } 42 | 43 | void 44 | kinetics_update (kinetics_t *kinetics, double delta) 45 | { 46 | double x = kinetics->x + cos (kinetics->angle) * kinetics->velocity * delta; 47 | double y = kinetics->y + sin (kinetics->angle) * kinetics->velocity * delta; 48 | double w = kinetics->width/2; 49 | 50 | if (x + w > kinetics->canvas_width) { 51 | if (kinetics->angle >= 0 && kinetics->angle < M_PI / 2) 52 | kinetics->angle = M_PI - kinetics->angle; 53 | else if (kinetics->angle > M_PI / 2 * 3) 54 | kinetics->angle -= (kinetics->angle - M_PI /2 * 3) * 2; 55 | x = kinetics->canvas_width - w; 56 | } 57 | 58 | if (x - w < 0) { 59 | if (kinetics->angle > M_PI / 2 && kinetics->angle < M_PI) 60 | kinetics->angle = M_PI - kinetics->angle; 61 | else if (kinetics->angle > M_PI && kinetics->angle < M_PI / 2 * 3) 62 | kinetics->angle += (M_PI / 2 * 3 - kinetics->angle) * 2; 63 | x = w; 64 | } 65 | 66 | if (y + w > kinetics->canvas_height) { 67 | if (kinetics->angle > 0 && kinetics->angle < 2 * M_PI) 68 | kinetics->angle = M_PI * 2 - kinetics->angle; 69 | y = kinetics->canvas_height - w; 70 | } 71 | 72 | if (y - w < 0) { 73 | if (kinetics->angle > M_PI && kinetics->angle < M_PI * 2) 74 | kinetics->angle = kinetics->angle - (kinetics->angle - M_PI) * 2; 75 | y = w; 76 | } 77 | 78 | kinetics->x = x; 79 | kinetics->y = y; 80 | 81 | kinetics->rotation += M_PI / 9; 82 | if (kinetics->rotation > 2 * M_PI) 83 | kinetics->rotation -= 2 * M_PI; 84 | } 85 | 86 | /* 87 | Local Variables: 88 | mode:c++ 89 | c-file-style:"stroustrup" 90 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 91 | indent-tabs-mode:nil 92 | fill-column:99 93 | End: 94 | */ 95 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 96 | -------------------------------------------------------------------------------- /src/kinetics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __KINETICS_H__ 8 | #define __KINETICS_H__ 9 | #include 10 | typedef struct _kinetics 11 | { 12 | double angle; 13 | double velocity; 14 | double x; 15 | double y; 16 | double color[4]; 17 | 18 | double rotation; 19 | 20 | double x_radius; 21 | double y_radius; 22 | double width; 23 | double height; 24 | double canvas_width; 25 | double canvas_height; 26 | double line_width; 27 | } kinetics_t; 28 | 29 | void kinetics_init (kinetics_t *kinetics, const caskbench_context_t *ctx); 30 | void kinetics_update (kinetics_t *kinetics, double delta); 31 | void kinetics_destroy(kinetics_t *kinetics); 32 | 33 | #endif // __KINETICS_H__ 34 | /* 35 | Local Variables: 36 | mode:c++ 37 | c-file-style:"stroustrup" 38 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 39 | indent-tabs-mode:nil 40 | fill-column:99 41 | End: 42 | */ 43 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 44 | -------------------------------------------------------------------------------- /src/rnd.h: -------------------------------------------------------------------------------- 1 | #ifndef RND_H_ 2 | #define RND_H_ 3 | 4 | void srnd(void); 5 | unsigned int rnd(void); 6 | double drnd48(void); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /src/shapes.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | #include 9 | 10 | #include "shapes.h" 11 | 12 | const char *gFillTypes[] = { 13 | "random", 14 | "none", 15 | "solid", 16 | "linear-gradient", 17 | "radial-gradient", 18 | "image-pattern", 19 | "herringbone-pattern", 20 | NULL 21 | }; 22 | 23 | fill_type_t 24 | convertToFillType(const char *fill_name) 25 | { 26 | int i =0; 27 | if (fill_name == NULL) 28 | return (fill_type_t) 0; 29 | while (gFillTypes[i] != NULL) { 30 | if (strcmp(gFillTypes[i], fill_name) == 0) 31 | return (fill_type_t) i ; 32 | i++; 33 | } 34 | errx(1, "Unknown fill type '%s' specified", fill_name); 35 | } 36 | 37 | const char *gShapes[] = { 38 | "random", 39 | "circle", 40 | "rectangle", 41 | "triangle", 42 | "star", 43 | "roundedrectangle", 44 | NULL 45 | }; 46 | 47 | shape_type_t 48 | convertToShapeType(const char* shape_name) 49 | { 50 | int i =0; 51 | if (shape_name == NULL) 52 | return (shape_type_t) 0; 53 | while (gShapes[i] != NULL) { 54 | if (strcmp(gShapes[i], shape_name) == 0) 55 | return (shape_type_t) (i); 56 | i++; 57 | } 58 | errx(1, "Unknown shape type '%s' specified", shape_name); 59 | } 60 | 61 | 62 | int star_points[11][2] = { 63 | { 0, 85 }, 64 | { 75, 75 }, 65 | { 100, 10 }, 66 | { 125, 75 }, 67 | { 200, 85 }, 68 | { 150, 125 }, 69 | { 160, 190 }, 70 | { 100, 150 }, 71 | { 40, 190 }, 72 | { 50, 125 }, 73 | { 0, 85 } 74 | }; 75 | 76 | void 77 | shape_init(shapes_t *shape) 78 | { 79 | memset(shape, 0, sizeof(shapes_t)); 80 | } 81 | 82 | void 83 | shape_copy(const shapes_t *src, shapes_t *dest) 84 | { 85 | *dest = *src; 86 | } 87 | 88 | void 89 | shape_randomize(shapes_t *shape) 90 | { 91 | // TODO 92 | } 93 | 94 | void 95 | generate_random_color(double &red, double &green, double &blue, double &alpha) 96 | { 97 | red = (double)rnd()/RAND_MAX; 98 | green = (double)rnd()/RAND_MAX; 99 | blue = (double)rnd()/RAND_MAX; 100 | alpha = (double)rnd()/RAND_MAX; 101 | } 102 | 103 | shape_type_t 104 | generate_random_shape() 105 | { 106 | return (shape_type_t) ((((double)(CB_SHAPE_END-1) * rnd())/RAND_MAX) + 1); 107 | } 108 | 109 | fill_type_t 110 | generate_random_fill_type() 111 | { 112 | return (fill_type_t) ((((double)(CB_FILL_END-1) * rnd())/RAND_MAX) + 1); 113 | } 114 | 115 | /* 116 | Local Variables: 117 | mode:c++ 118 | c-file-style:"stroustrup" 119 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 120 | indent-tabs-mode:nil 121 | fill-column:99 122 | End: 123 | */ 124 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 125 | -------------------------------------------------------------------------------- /src/shapes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __SHAPES_H_ 8 | #define __SHAPES_H_ 9 | #include 10 | #include 11 | 12 | #include "rnd.h" 13 | 14 | typedef enum { 15 | CB_FILL_RANDOM, 16 | CB_FILL_NONE, 17 | CB_FILL_SOLID, 18 | CB_FILL_LINEAR_GRADIENT, 19 | CB_FILL_RADIAL_GRADIENT, 20 | CB_FILL_IMAGE_PATTERN, 21 | #if 0 22 | CB_FILL_HERRINGBONE_PATTERN, 23 | #endif 24 | CB_FILL_END 25 | } fill_type_t; 26 | 27 | fill_type_t 28 | convertToFillType(const char *fill_name); 29 | 30 | typedef enum { 31 | CB_SHAPE_RANDOM, 32 | CB_SHAPE_CIRCLE, 33 | CB_SHAPE_RECTANGLE, 34 | CB_SHAPE_TRIANGLE, 35 | CB_SHAPE_STAR, 36 | CB_SHAPE_ROUNDED_RECTANGLE, 37 | CB_SHAPE_END 38 | } shape_type_t; 39 | 40 | shape_type_t 41 | convertToShapeType(const char* shape_name); 42 | 43 | typedef struct shapes 44 | { 45 | double x; 46 | double y; 47 | double radius; 48 | double width; 49 | double height; 50 | double dx1; 51 | double dy1; 52 | double dx2; 53 | double dy2; 54 | 55 | shape_type_t shape_type; 56 | fill_type_t fill_type; 57 | uint32_t fill_color; 58 | uint32_t stroke_color; 59 | int animation; 60 | int stroke_width; 61 | 62 | int dash_style; 63 | int cap_style; 64 | int join_style; 65 | } shapes_t; 66 | 67 | extern int star_points[11][2]; 68 | 69 | void 70 | shape_init(shapes_t *shape); 71 | 72 | void 73 | shape_copy(const shapes_t *shape_defaults, shapes_t *shape); 74 | 75 | void 76 | shape_randomize(shapes_t *shape); 77 | 78 | shape_type_t 79 | generate_random_shape(); 80 | 81 | void 82 | generate_random_color(double &red, double &green, double &blue, double &alpha); 83 | 84 | fill_type_t 85 | generate_random_fill_type(); 86 | 87 | #endif 88 | /* 89 | Local Variables: 90 | mode:c++ 91 | c-file-style:"stroustrup" 92 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 93 | indent-tabs-mode:nil 94 | fill-column:99 95 | End: 96 | */ 97 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 98 | -------------------------------------------------------------------------------- /src/skia-egl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include 18 | #if HAVE_GLES3_H 19 | #include 20 | #elif HAVE_GLES2_H 21 | #include 22 | #endif 23 | 24 | #include "egl.h" 25 | #include "device_config.h" 26 | 27 | static egl_state_t *state; 28 | static GrContext* ctx; 29 | 30 | SkBaseDevice * 31 | create_skia_device_egl (const device_config_t& config) 32 | { 33 | GrBackendRenderTargetDesc desc; 34 | GrRenderTarget* target; 35 | SkGpuDevice *device; 36 | 37 | state = (egl_state_t*) malloc (sizeof (egl_state_t)); 38 | if (!state) { 39 | warnx ("Out of memory\n"); 40 | return NULL; 41 | } 42 | 43 | if (!createEGLContextAndWindow(state, config)) { 44 | cleanup_state_egl(state); 45 | return NULL; 46 | } 47 | 48 | eglMakeCurrent(state->egl_display, state->egl_surface, state->egl_surface, state->egl_context); 49 | 50 | desc.fWidth = config.width; 51 | desc.fHeight = config.height; 52 | desc.fConfig = kSkia8888_GrPixelConfig; 53 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 54 | desc.fStencilBits = 1; 55 | desc.fRenderTargetHandle = 0; 56 | if (config.egl_sample_buffers > 0) 57 | desc.fSampleCnt = config.egl_samples; 58 | else 59 | desc.fSampleCnt = 0; 60 | 61 | ctx = GrContext::Create(kOpenGL_GrBackend, 0); 62 | if (!ctx) { 63 | cleanup_state_egl(state); 64 | errx(-1, "Could not establish a graphics context for Skia EGL\n"); 65 | } 66 | 67 | target = ctx->wrapBackendRenderTarget(desc); 68 | device = new SkGpuDevice(ctx, target); 69 | 70 | glClearColor(1, 1, 1, 1); 71 | glClear(GL_COLOR_BUFFER_BIT); 72 | 73 | return device; 74 | } 75 | 76 | void 77 | destroy_skia_egl(void) 78 | { 79 | delete ctx; 80 | cleanup_state_egl(state); 81 | } 82 | 83 | void 84 | update_skia_egl(void) 85 | { 86 | ctx->flush(); 87 | eglSwapBuffers(state->egl_display, state->egl_surface); 88 | } 89 | 90 | /* 91 | Local Variables: 92 | mode:c++ 93 | c-file-style:"stroustrup" 94 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 95 | indent-tabs-mode:nil 96 | fill-column:99 97 | End: 98 | */ 99 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 100 | -------------------------------------------------------------------------------- /src/skia-glx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "glx.h" 18 | #include "device_config.h" 19 | 20 | static glx_state_t *state; 21 | GrContext* ctx; 22 | 23 | SkBaseDevice * 24 | create_skia_device_glx (const device_config_t& config) 25 | { 26 | GrBackendRenderTargetDesc desc; 27 | GrRenderTarget* target; 28 | SkGpuDevice *device; 29 | 30 | state = (glx_state_t*) malloc (sizeof (glx_state_t)); 31 | if (!state) { 32 | warnx("Out of memory\n"); 33 | return NULL; 34 | } 35 | 36 | if (!createGLXContextAndWindow(state, config.width, config.height)) { 37 | cleanup_state_glx(state); 38 | errx("Could not create GLX context and window\n"); 39 | } 40 | 41 | // TODO: See SkOSWindow_Unix.cpp 42 | 43 | glXMakeCurrent(state->dpy, state->window, state->glx_context); 44 | 45 | desc.fWidth = config.width; 46 | desc.fHeight = config.height; 47 | desc.fConfig = kSkia8888_GrPixelConfig; 48 | desc.fOrigin = kBottomLeft_GrSurfaceOrigin; 49 | desc.fStencilBits = 1; 50 | desc.fRenderTargetHandle = 0; 51 | desc.fSampleCnt = 0; 52 | 53 | ctx = GrContext::Create(kOpenGL_GrBackend, 0); 54 | if (!ctx) { 55 | cleanup_state_glx(state); 56 | errx("Could not create Gr context for kOpenGL_GrBackend\n"); 57 | } 58 | 59 | target = ctx->wrapBackendRenderTarget(desc); 60 | device = new SkGpuDevice(ctx, target); 61 | 62 | //glClearStencil(0); 63 | glClearColor(1, 1, 1, 1); 64 | glClear(GL_COLOR_BUFFER_BIT); 65 | 66 | return device; 67 | } 68 | 69 | void 70 | destroy_skia_glx(void) 71 | { 72 | delete ctx; 73 | cleanup_state_glx(state); 74 | } 75 | 76 | void 77 | update_skia_glx(void) 78 | { 79 | ctx->flush(); 80 | //glxSwapBuffers(state->glx_display, state->glx_surface); // TODO: ? 81 | } 82 | 83 | /* 84 | Local Variables: 85 | mode:c++ 86 | c-file-style:"stroustrup" 87 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 88 | indent-tabs-mode:nil 89 | fill-column:99 90 | End: 91 | */ 92 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 93 | -------------------------------------------------------------------------------- /src/skia-image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | #include "forward.h" 15 | #include "image.h" 16 | 17 | static image_state_t *state; 18 | SkBitmap skia_bitmap; 19 | 20 | static bool 21 | convert_skbitmap_to_ximage(const SkBitmap& bitmap) { 22 | sk_bzero(&state->image, sizeof(state->image)); 23 | 24 | int bitsPerPixel = bitmap.bytesPerPixel() * 8; 25 | state->image.width = bitmap.width(); 26 | state->image.height = bitmap.height(); 27 | state->image.format = ZPixmap; 28 | state->image.data = (char*) bitmap.getPixels(); 29 | state->image.byte_order = LSBFirst; 30 | state->image.bitmap_unit = 4 * 8; 31 | state->image.bitmap_bit_order = LSBFirst; 32 | state->image.bitmap_pad = 4 * 8; 33 | state->image.depth = 32; 34 | state->image.bytes_per_line = bitmap.width() * 4; 35 | state->image.bits_per_pixel = 4 * 8; 36 | return XInitImage(&state->image); 37 | } 38 | 39 | 40 | SkBaseDevice * 41 | create_skia_device_image (const device_config_t& config) 42 | { 43 | state = (image_state_t*) malloc (sizeof (image_state_t)); 44 | if (!state) { 45 | warnx ("Out of memory\n"); 46 | return NULL; 47 | } 48 | 49 | if (!skia_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 50 | config.width, config.height)) { 51 | warnx("Failed to configure bitmap\n"); 52 | return NULL; 53 | } 54 | SkImageInfo info = SkImageInfo::Make(config.width, config.height, 55 | kBGRA_8888_SkColorType, 56 | kPremul_SkAlphaType); 57 | if (! skia_bitmap.allocPixels(info)) { 58 | warnx("Failed to allocate pixels\n"); 59 | return NULL; 60 | } 61 | 62 | if (!createImageWindow(state, config)) { 63 | cleanup_state_image(state); 64 | return NULL; 65 | } 66 | 67 | return new SkBitmapDevice (skia_bitmap); 68 | } 69 | 70 | void 71 | destroy_skia_image(void) 72 | { 73 | destroyImageWindow(state); 74 | cleanup_state_image(state); 75 | } 76 | 77 | void 78 | update_skia_image(void) 79 | { 80 | if (convert_skbitmap_to_ximage (skia_bitmap)) { 81 | updateImageWindow(state); 82 | } 83 | } 84 | 85 | /* 86 | Local Variables: 87 | mode:c++ 88 | c-file-style:"stroustrup" 89 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 90 | indent-tabs-mode:nil 91 | fill-column:99 92 | End: 93 | */ 94 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 95 | -------------------------------------------------------------------------------- /src/skia-shapes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __SKIA_SHAPES_H_ 8 | #define __SKIA_SHAPES_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "forward.h" 14 | #include "shapes.h" 15 | 16 | SkColor skiaRandomColor(); 17 | 18 | void skiaRandomizePaintColor(caskbench_context_t *ctx); 19 | 20 | void sk_set_fill_style(caskbench_context_t *ctx, const shapes_t *shape); 21 | 22 | SkShader *skiaCreateLinearGradientShader(int y1, int y2); 23 | 24 | SkShader *skiaCreateRadialGradientShader(const shapes_t *shape); 25 | 26 | SkShader *skiaCreateBitmapShader(const char *image_path); 27 | void skiaDrawLine(caskbench_context_t *ctx, shapes_t *args); 28 | 29 | void skiaDrawQuadraticCurve(caskbench_context_t *ctx, shapes_t *args); 30 | 31 | void skiaDrawCubicCurve(caskbench_context_t *ctx, shapes_t *args); 32 | 33 | void skiaDrawCircle(caskbench_context_t *ctx, shapes_t *args); 34 | 35 | void skiaDrawRectangle(caskbench_context_t *ctx, shapes_t *args); 36 | 37 | void skiaDrawTriangle(caskbench_context_t *ctx, shapes_t *args); 38 | 39 | void skiaDrawStar(caskbench_context_t *ctx, shapes_t *args); 40 | 41 | void skiaDrawRoundedRectangle(caskbench_context_t *ctx, shapes_t *args); 42 | 43 | SkBitmap skiaCreateSampleImage(caskbench_context_t *ctx); 44 | 45 | SkPath getCurrentSkiaPath(); 46 | 47 | extern void (*skiaShapes[CB_SHAPE_END-1])(caskbench_context_t *ctx , shapes_t *args); 48 | 49 | void skiaDrawRandomizedShape(caskbench_context_t *ctx, shapes_t *shape); 50 | 51 | #endif 52 | /* 53 | Local Variables: 54 | mode:c++ 55 | c-file-style:"stroustrup" 56 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 57 | indent-tabs-mode:nil 58 | fill-column:99 59 | End: 60 | */ 61 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 62 | -------------------------------------------------------------------------------- /src/skia-tests/animation.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "forward.h" 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "skia-shapes.h" 16 | #include "kinetics.h" 17 | 18 | static kinetics_t *particles; 19 | 20 | int 21 | sk_setup_animation(caskbench_context_t *ctx) 22 | { 23 | if (ctx->size <= 0) 24 | return 0; 25 | 26 | // Animation setup 27 | particles = (kinetics_t *) malloc (sizeof (kinetics_t) * ctx->size); 28 | for (int i = 0; i < ctx->size; i++) 29 | kinetics_init(&particles[i], ctx); 30 | 31 | return 1; 32 | } 33 | 34 | void 35 | sk_teardown_animation(void) 36 | { 37 | free(particles); 38 | } 39 | 40 | int 41 | sk_test_animation(caskbench_context_t *ctx) 42 | { 43 | static int counter = 0; 44 | // Animation / Kinematics of single or multi shape 45 | ctx->skia_canvas->drawColor(SK_ColorBLACK); 46 | 47 | for (int i = 0; i < ctx->size; i++) { 48 | shapes_t shape; 49 | kinetics_t *particle = &particles[i]; 50 | 51 | kinetics_update(particle, 0.1); 52 | 53 | shape_copy(&ctx->shape_defaults, &shape); 54 | shape.width = particle->width; 55 | shape.height = particle->height; 56 | shape.x = particle->x; 57 | shape.y = particle->y; 58 | if (!shape.radius) 59 | shape.radius = 40; 60 | 61 | /* canvas save and restore creates different outputs */ 62 | //ctx->skia_canvas->save(); 63 | ctx->skia_canvas->rotate(counter/50.0); 64 | skiaDrawRandomizedShape(ctx, &shape); 65 | //ctx->skia_canvas->restore(); 66 | counter++; 67 | } 68 | 69 | return 1; 70 | } 71 | 72 | /* 73 | Local Variables: 74 | mode:c++ 75 | c-file-style:"stroustrup" 76 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 77 | indent-tabs-mode:nil 78 | fill-column:99 79 | End: 80 | */ 81 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 82 | -------------------------------------------------------------------------------- /src/skia-tests/bubbles.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | // From http://www.atoker.com/blog/2008/09/06/skia-graphics-library-in-chrome-first-impressions/ 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "skia-shapes.h" 16 | 17 | static int max_dim; 18 | 19 | int 20 | sk_setup_bubbles(caskbench_context_t *ctx) 21 | { 22 | max_dim = MIN(ctx->canvas_width, ctx->canvas_height)/2; 23 | return 1; 24 | } 25 | 26 | void 27 | sk_teardown_bubbles(void) 28 | { 29 | } 30 | 31 | int 32 | sk_test_bubbles(caskbench_context_t *ctx) 33 | { 34 | int i, x, y, r; 35 | for (i=0; isize; i++) { 36 | skiaRandomizePaintColor(ctx); 37 | 38 | r = ((double)max_dim*rnd())/RAND_MAX + 1; 39 | x = (0.5*(double)ctx->canvas_width*rnd())/RAND_MAX; 40 | y = (0.5*(double)ctx->canvas_height*rnd())/RAND_MAX; 41 | ctx->skia_canvas->drawCircle(x, y, r, *ctx->skia_paint); 42 | } 43 | 44 | return 1; 45 | } 46 | 47 | /* 48 | Local Variables: 49 | mode:c++ 50 | c-file-style:"stroustrup" 51 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 52 | indent-tabs-mode:nil 53 | fill-column:99 54 | End: 55 | */ 56 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 57 | -------------------------------------------------------------------------------- /src/skia-tests/circle.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_circle(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_circle(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_circle(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | for (int i=0; isize; i++) { 42 | shape.x = (double)rnd()/RAND_MAX * w; 43 | shape.y = (double)rnd()/RAND_MAX * h; 44 | shape.radius = (double)rnd()/RAND_MAX * MIN( 45 | MIN(shape.x, w-shape.x), MIN(shape.y, h-shape.y)); 46 | 47 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 48 | shape.fill_type = generate_random_fill_type(); 49 | } 50 | sk_set_fill_style(ctx, &shape); 51 | 52 | shape.shape_type = CB_SHAPE_CIRCLE; 53 | skiaDrawRandomizedShape(ctx,&shape); 54 | } 55 | 56 | return 1; 57 | } 58 | 59 | /* 60 | Local Variables: 61 | mode:c++ 62 | c-file-style:"stroustrup" 63 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 64 | indent-tabs-mode:nil 65 | fill-column:99 66 | End: 67 | */ 68 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 69 | -------------------------------------------------------------------------------- /src/skia-tests/clip.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "skia-shapes.h" 17 | 18 | static SkBitmap bitmap; 19 | 20 | int 21 | sk_setup_clip(caskbench_context_t *ctx) 22 | { 23 | ctx->skia_paint->setAntiAlias(false); 24 | bitmap = skiaCreateSampleImage (ctx); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_clip(void) 30 | { 31 | } 32 | 33 | #if 1 34 | // Single static star and random clip 35 | int 36 | sk_test_clip(caskbench_context_t *ctx) 37 | { 38 | int w = ctx->canvas_width; 39 | int h = ctx->canvas_height; 40 | 41 | double ratio; 42 | ratio = (double) w/h; 43 | shapes_t shape; 44 | double scale_param_x = w/80; 45 | double scale_param_y; 46 | 47 | shape_copy(&ctx->shape_defaults, &shape); 48 | ctx->skia_canvas->save(); 49 | 50 | /* Draw star for the full screen size */ 51 | if (ratio > 1.0) 52 | scale_param_y = scale_param_x * (1/ratio); 53 | else if (ratio < 1.0) 54 | scale_param_y = scale_param_x + (ratio); 55 | else 56 | scale_param_y = scale_param_x; 57 | ctx->skia_canvas->scale(scale_param_x,scale_param_y); 58 | 59 | shape.x = 0; 60 | shape.y = 0; 61 | shape.radius = 40; 62 | shape.shape_type = CB_SHAPE_STAR; 63 | shape.fill_type = CB_FILL_SOLID; 64 | 65 | sk_set_fill_style(ctx, &shape); 66 | skiaDrawRandomizedShape(ctx, &shape); 67 | 68 | for (int i=0; isize; i++) { 69 | ctx->skia_canvas->clipPath(getCurrentSkiaPath(), SkRegion::kReplace_Op, true); 70 | double x1 = (double)rnd()/RAND_MAX * w; 71 | double x2 = (double)rnd()/RAND_MAX * w; 72 | double y1 = (double)rnd()/RAND_MAX * h; 73 | double y2 = (double)rnd()/RAND_MAX * h; 74 | ctx->skia_canvas->drawBitmap(bitmap, x1, y1); 75 | } 76 | ctx->skia_canvas->restore(); 77 | 78 | return 1; 79 | } 80 | 81 | #else 82 | // Random stars and random clip 83 | int 84 | sk_test_clip(caskbench_context_t *ctx) 85 | { 86 | int w = ctx->canvas_width; 87 | int h = ctx->canvas_height; 88 | 89 | shapes_t shape; 90 | shape_copy(&ctx->shape_defaults, &shape); 91 | ctx->skia_canvas->drawColor(SK_ColorBLACK); 92 | 93 | for (int i=0; isize; i++) { 94 | double i = (double)rnd()/RAND_MAX * w; 95 | double j = (double)rnd()/RAND_MAX * h; 96 | ctx->skia_canvas->save(); 97 | ctx->skia_canvas->translate(i, j); 98 | ctx->skia_canvas->scale(0.5,0.5); 99 | 100 | shape.x = 0; 101 | shape.y = 0; 102 | shape.radius = 40; 103 | shape.shape_type = CB_SHAPE_STAR; 104 | shape.fill_type = CB_FILL_SOLID; 105 | 106 | sk_set_fill_style(ctx, &shape); 107 | skiaDrawRandomizedShape(ctx, &shape); 108 | 109 | ctx->skia_canvas->clipPath(getCurrentSkiaPath(), SkRegion::kReplace_Op, true); 110 | double x1 = (double)rnd()/RAND_MAX * 80; 111 | double y1 = (double)rnd()/RAND_MAX * 80; 112 | ctx->skia_canvas->drawBitmap(bitmap, x1, y1); 113 | ctx->skia_canvas->restore(); 114 | } 115 | 116 | return 1; 117 | } 118 | #endif 119 | /* 120 | Local Variables: 121 | mode:c++ 122 | c-file-style:"stroustrup" 123 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 124 | indent-tabs-mode:nil 125 | fill-column:99 126 | End: 127 | */ 128 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 129 | -------------------------------------------------------------------------------- /src/skia-tests/cubic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_cubic(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | if (ctx->shape_defaults.fill_type == CB_FILL_SOLID) { 26 | ctx->skia_paint->setStyle(SkPaint::kFill_Style); 27 | } 28 | 29 | return 1; 30 | } 31 | 32 | void 33 | sk_teardown_cubic(void) 34 | { 35 | } 36 | 37 | int 38 | sk_test_cubic(caskbench_context_t *ctx) 39 | { 40 | int w = ctx->canvas_width; 41 | int h = ctx->canvas_height; 42 | 43 | shapes_t shape; 44 | shape_copy(&ctx->shape_defaults, &shape); 45 | for (int i=0; isize; i++) { 46 | shape.x = (double)rnd()/RAND_MAX * w; 47 | shape.dx1 = (double)rnd()/RAND_MAX * w; 48 | shape.dx2 = (double)rnd()/RAND_MAX * w; 49 | shape.width = (double)rnd()/RAND_MAX * w - shape.x; 50 | shape.y = (double)rnd()/RAND_MAX * h; 51 | shape.dy1 = (double)rnd()/RAND_MAX * h; 52 | shape.dy2 = (double)rnd()/RAND_MAX * h; 53 | shape.height = (double)rnd()/RAND_MAX * h - shape.y; 54 | 55 | skiaRandomizePaintColor(ctx); 56 | skiaDrawCubicCurve(ctx, &shape); 57 | } 58 | 59 | return 1; 60 | } 61 | 62 | /* 63 | Local Variables: 64 | mode:c++ 65 | c-file-style:"stroustrup" 66 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 67 | indent-tabs-mode:nil 68 | fill-column:99 69 | End: 70 | */ 71 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 72 | -------------------------------------------------------------------------------- /src/skia-tests/curves.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | static double delta = 0; 20 | 21 | int 22 | sk_setup_curves(caskbench_context_t *ctx) 23 | { 24 | ctx->skia_paint->setAntiAlias(false); 25 | ctx->skia_paint->setStrokeWidth(1); 26 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 27 | return 1; 28 | } 29 | 30 | void 31 | sk_teardown_curves(void) 32 | { 33 | } 34 | 35 | int 36 | sk_test_curves(caskbench_context_t *ctx) 37 | { 38 | SkPath path; 39 | int cp = ctx->canvas_width / 2; // center point 40 | int rr = ctx->canvas_width / 2; 41 | int nn = 32; // must be even 42 | double step = (2 * M_PI) / nn; 43 | 44 | 45 | for (int i=0; isize; i++) { 46 | double angle = delta; // in radians 47 | double x = cp + rr * cos(angle); 48 | double y = cp + rr * sin(angle); 49 | 50 | 51 | // begin path 52 | SkPath path; 53 | path.moveTo(SkDoubleToScalar(x), SkDoubleToScalar(y)); 54 | 55 | // segments 56 | for (int j=0; jshape_defaults.fill_type == CB_FILL_SOLID) { 74 | ctx->skia_paint->setStyle(SkPaint::kStrokeAndFill_Style); 75 | } 76 | 77 | path.close(); 78 | ctx->skia_canvas->drawPath(path, *(ctx->skia_paint)); 79 | } 80 | delta += 0.5; 81 | 82 | return 1; 83 | } 84 | 85 | /* 86 | Local Variables: 87 | mode:c++ 88 | c-file-style:"stroustrup" 89 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 90 | indent-tabs-mode:nil 91 | fill-column:99 92 | End: 93 | */ 94 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 95 | -------------------------------------------------------------------------------- /src/skia-tests/fill.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "forward.h" 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "skia-shapes.h" 16 | #include "kinetics.h" 17 | 18 | static kinetics_t *skia_particles; 19 | static int element_spacing; 20 | static int num_x_elements; 21 | static int num_y_elements; 22 | 23 | /* TODO: 24 | * - Specify with or without alpha 25 | * - With or without antialiasing? 26 | * - Stroke width should be via the shape defaults 27 | */ 28 | 29 | int 30 | sk_setup_fill(caskbench_context_t *ctx) 31 | { 32 | if (ctx->size <= 0) 33 | return 0; 34 | 35 | return 1; 36 | } 37 | 38 | void 39 | sk_teardown_fill(void) 40 | { 41 | } 42 | 43 | int 44 | sk_test_fill(caskbench_context_t *ctx) 45 | { 46 | for (int i = 0; i < ctx->size; i++) 47 | { 48 | shapes_t shape; 49 | shape_copy(&ctx->shape_defaults, &shape); 50 | 51 | if (!(shape.x && shape.y)) 52 | { 53 | shape.x = ctx->canvas_width/2; 54 | shape.y = ctx->canvas_height/2; 55 | } 56 | if (!(shape.width && shape.height)) 57 | { 58 | shape.width = 100; 59 | shape.height = 50; 60 | } 61 | if (!shape.radius) 62 | shape.radius = 40; 63 | 64 | /* Height is used for creating patterns, needs to be updated for star and triangle */ 65 | if (shape.shape_type == CB_SHAPE_STAR || shape.shape_type == CB_SHAPE_TRIANGLE) 66 | shape.height = 2*shape.radius; 67 | 68 | /* Use rectangle as default shape */ 69 | shape.shape_type = shape.shape_type ? shape.shape_type:CB_SHAPE_RECTANGLE; 70 | skiaDrawRandomizedShape(ctx, &shape); 71 | } 72 | 73 | return 1; 74 | } 75 | 76 | /* 77 | Local Variables: 78 | mode:c++ 79 | c-file-style:"stroustrup" 80 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 81 | indent-tabs-mode:nil 82 | fill-column:99 83 | End: 84 | */ 85 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 86 | -------------------------------------------------------------------------------- /src/skia-tests/hline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_hline(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_hline(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_hline(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | for (int i=0; isize; i++) { 42 | double x1 = (double)rnd()/RAND_MAX * w; 43 | double x2 = (double)rnd()/RAND_MAX * w; 44 | double y = (double)rnd()/RAND_MAX * h; 45 | 46 | shape.x = x1; 47 | shape.y = y; 48 | shape.width = x1 - x2; 49 | shape.height = 0; 50 | 51 | skiaRandomizePaintColor(ctx); 52 | skiaDrawLine(ctx, &shape); 53 | } 54 | 55 | return 1; 56 | } 57 | 58 | /* 59 | Local Variables: 60 | mode:c++ 61 | c-file-style:"stroustrup" 62 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 63 | indent-tabs-mode:nil 64 | fill-column:99 65 | End: 66 | */ 67 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 68 | -------------------------------------------------------------------------------- /src/skia-tests/image-rotate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include "caskbench.h" 10 | #include "caskbench_context.h" 11 | #include "skia-shapes.h" 12 | 13 | static SkBitmap bitmap; 14 | 15 | int 16 | sk_setup_image_rotate(caskbench_context_t *ctx) 17 | { 18 | bitmap = skiaCreateSampleImage (ctx); 19 | return 1; 20 | } 21 | 22 | void 23 | sk_teardown_image_rotate(void) 24 | { 25 | } 26 | 27 | int 28 | sk_test_image_rotate(caskbench_context_t *ctx) 29 | { 30 | static int counter = 0; 31 | int w = ctx->canvas_width; 32 | int h = ctx->canvas_height; 33 | int iw = bitmap.width(); 34 | int ih = bitmap.height(); 35 | int pw = w - iw; 36 | int ph = h - ih; 37 | 38 | for (int i=0; isize; i++) { 39 | double x = (double)rnd()/RAND_MAX * pw; 40 | double y = (double)rnd()/RAND_MAX * ph; 41 | 42 | ctx->skia_canvas->save(); 43 | ctx->skia_canvas->translate(w/2, h/2); 44 | ctx->skia_canvas->rotate(SkDoubleToScalar(counter/(50.0))); 45 | ctx->skia_canvas->translate(-iw/2, -ih/2); 46 | 47 | ctx->skia_canvas->drawBitmap(bitmap, 0, 0); 48 | ctx->skia_canvas->restore(); 49 | counter++; 50 | } 51 | 52 | return 1; 53 | } 54 | 55 | /* 56 | Local Variables: 57 | mode:c++ 58 | c-file-style:"stroustrup" 59 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 60 | indent-tabs-mode:nil 61 | fill-column:99 62 | End: 63 | */ 64 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 65 | -------------------------------------------------------------------------------- /src/skia-tests/image-scale.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "skia-shapes.h" 17 | 18 | static SkBitmap bitmap; 19 | 20 | int 21 | sk_setup_image_scale(caskbench_context_t *ctx) 22 | { 23 | bitmap = skiaCreateSampleImage (ctx); 24 | return 1; 25 | } 26 | 27 | void 28 | sk_teardown_image_scale(void) 29 | { 30 | } 31 | 32 | int 33 | sk_test_image_scale(caskbench_context_t *ctx) 34 | { 35 | int w = ctx->canvas_width; 36 | int h = ctx->canvas_height; 37 | SkRect r; 38 | 39 | for (int i=0; isize; i++) { 40 | double x1 = (double)rnd()/RAND_MAX * w; 41 | double x2 = (double)rnd()/RAND_MAX * w; 42 | double y1 = (double)rnd()/RAND_MAX * h; 43 | double y2 = (double)rnd()/RAND_MAX * h; 44 | double x = MIN(x1, x2); 45 | double y = MIN(y1, y2); 46 | r.set(x, y, x + fabs(x2 - x1), y + fabs(y2 - y1)); 47 | ctx->skia_canvas->drawBitmapRect(bitmap, r, ctx->skia_paint); 48 | } 49 | 50 | return 1; 51 | } 52 | 53 | /* 54 | Local Variables: 55 | mode:c++ 56 | c-file-style:"stroustrup" 57 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 58 | indent-tabs-mode:nil 59 | fill-column:99 60 | End: 61 | */ 62 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 63 | -------------------------------------------------------------------------------- /src/skia-tests/image.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "caskbench.h" 15 | #include "caskbench_context.h" 16 | #include "skia-shapes.h" 17 | 18 | static SkBitmap bitmap; 19 | 20 | int 21 | sk_setup_image(caskbench_context_t *ctx) 22 | { 23 | bitmap = skiaCreateSampleImage (ctx); 24 | return 1; 25 | } 26 | 27 | void 28 | sk_teardown_image(void) 29 | { 30 | } 31 | 32 | int 33 | sk_test_image(caskbench_context_t *ctx) 34 | { 35 | int w = ctx->canvas_width; 36 | int h = ctx->canvas_height; 37 | int iw = bitmap.width(); 38 | int ih = bitmap.height(); 39 | int pw = w - iw; 40 | int ph = h - ih; 41 | 42 | for (int i=0; isize; i++) { 43 | double x = (double)rnd()/RAND_MAX * pw; 44 | double y = (double)rnd()/RAND_MAX * ph; 45 | 46 | ctx->skia_canvas->drawBitmap(bitmap, x, y); 47 | } 48 | 49 | return 1; 50 | } 51 | 52 | /* 53 | Local Variables: 54 | mode:c++ 55 | c-file-style:"stroustrup" 56 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 57 | indent-tabs-mode:nil 58 | fill-column:99 59 | End: 60 | */ 61 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 62 | -------------------------------------------------------------------------------- /src/skia-tests/line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_line(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_line(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_line(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | for (int i=0; isize; i++) { 42 | double x1 = (double)rnd()/RAND_MAX * w; 43 | double x2 = (double)rnd()/RAND_MAX * w; 44 | double y1 = (double)rnd()/RAND_MAX * h; 45 | double y2 = (double)rnd()/RAND_MAX * h; 46 | 47 | shape.x = x1; 48 | shape.y = y1; 49 | shape.width = x1 - x2; 50 | shape.height = y1 - y2; 51 | 52 | skiaRandomizePaintColor(ctx); 53 | skiaDrawLine(ctx, &shape); 54 | } 55 | 56 | return 1; 57 | } 58 | 59 | /* 60 | Local Variables: 61 | mode:c++ 62 | c-file-style:"stroustrup" 63 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 64 | indent-tabs-mode:nil 65 | fill-column:99 66 | End: 67 | */ 68 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 69 | -------------------------------------------------------------------------------- /src/skia-tests/linear-gradient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "caskbench.h" 17 | #include "caskbench_context.h" 18 | #include "skia-shapes.h" 19 | 20 | /* TODO: 21 | * - Specify with or without alpha 22 | * - With or without antialiasing? 23 | * - Stroke width should be via the shape defaults 24 | */ 25 | 26 | int 27 | sk_setup_linear_gradient(caskbench_context_t *ctx) 28 | { 29 | return 1; 30 | } 31 | 32 | void 33 | sk_teardown_linear_gradient(void) 34 | { 35 | } 36 | 37 | int 38 | sk_test_linear_gradient(caskbench_context_t *ctx) 39 | { 40 | int w = ctx->canvas_width; 41 | int h = ctx->canvas_height; 42 | int stops = 10; 43 | 44 | SkPoint pts[2]; 45 | pts[0].iset(0, 0); 46 | pts[1].iset(100, 100); 47 | SkColor colors[10]; 48 | SkScalar pos[10]; 49 | 50 | for (int i = 0; i < stops; i++) { 51 | pos[i] = i / SkIntToScalar(stops - 1); 52 | colors[i] = skiaRandomColor(); 53 | } 54 | 55 | SkShader *shader = SkGradientShader::CreateLinear(pts, colors, pos, stops, 56 | SkShader::kClamp_TileMode); 57 | ctx->skia_paint->setShader(shader); 58 | 59 | shapes_t shape; 60 | shape_copy(&ctx->shape_defaults, &shape); 61 | for (int i=0; isize; i++) { 62 | double x1 = (double)rnd()/RAND_MAX * w; 63 | double x2 = (double)rnd()/RAND_MAX * w; 64 | double y1 = (double)rnd()/RAND_MAX * h; 65 | double y2 = (double)rnd()/RAND_MAX * h; 66 | 67 | double xx = MIN(x1, x2); 68 | double yy = MIN(x1, x2); 69 | double ww = abs(x2 - x1); 70 | double hh = abs(y2 - y1); 71 | 72 | ctx->skia_canvas->save(); 73 | ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy)); 74 | ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100)); 75 | 76 | // transform(shape.width/100, 0, 0, shape.height/100, 0, 0) 77 | shape.x = 0; 78 | shape.y = 0; 79 | shape.width = 100; 80 | shape.height = 100; 81 | shape.fill_type = CB_FILL_LINEAR_GRADIENT; 82 | 83 | ctx->skia_paint->setStyle(SkPaint::kFill_Style); 84 | ctx->skia_paint->setShader(shader); 85 | 86 | skiaDrawRectangle(ctx, &shape); 87 | 88 | ctx->skia_canvas->restore(); 89 | } 90 | if (shader) 91 | shader->unref(); 92 | 93 | return 1; 94 | } 95 | 96 | /* 97 | Local Variables: 98 | mode:c++ 99 | c-file-style:"stroustrup" 100 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 101 | indent-tabs-mode:nil 102 | fill-column:99 103 | End: 104 | */ 105 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 106 | -------------------------------------------------------------------------------- /src/skia-tests/mask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "skia-shapes.h" 16 | 17 | int 18 | sk_setup_mask(caskbench_context_t *ctx) 19 | { 20 | SkMaskFilter *mask = SkStippleMaskFilter::Create(); 21 | ctx->skia_paint->setMaskFilter(mask); 22 | return 1; 23 | } 24 | 25 | void 26 | sk_teardown_mask(void) 27 | { 28 | } 29 | 30 | int 31 | sk_test_mask(caskbench_context_t *ctx) 32 | { 33 | int i; 34 | 35 | for (i=0; isize; i++) { 36 | skiaRandomizePaintColor(ctx); 37 | 38 | // Apply mask on a circle 39 | ctx->skia_canvas->drawCircle(40*i, 40, 30, *ctx->skia_paint); 40 | } 41 | 42 | return 1; 43 | } 44 | 45 | /* 46 | Local Variables: 47 | mode:c++ 48 | c-file-style:"stroustrup" 49 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 50 | indent-tabs-mode:nil 51 | fill-column:99 52 | End: 53 | */ 54 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 55 | -------------------------------------------------------------------------------- /src/skia-tests/multi-line.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_multi_line(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_multi_line(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_multi_line(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | double x = (double)rnd()/RAND_MAX * w; 39 | double y = (double)rnd()/RAND_MAX * h; 40 | SkPath path; 41 | 42 | path.moveTo(x, y); 43 | for (int i=0; isize; i++) { 44 | x = (double)rnd()/RAND_MAX * w; 45 | y = (double)rnd()/RAND_MAX * h; 46 | 47 | path.lineTo(x, y); 48 | } 49 | 50 | skiaRandomizePaintColor(ctx); 51 | ctx->skia_canvas->drawPath(path, *(ctx->skia_paint)); 52 | 53 | return 1; 54 | } 55 | 56 | /* 57 | Local Variables: 58 | mode:c++ 59 | c-file-style:"stroustrup" 60 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 61 | indent-tabs-mode:nil 62 | fill-column:99 63 | End: 64 | */ 65 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 66 | -------------------------------------------------------------------------------- /src/skia-tests/multi-shape.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "forward.h" 13 | #include "caskbench.h" 14 | #include "caskbench_context.h" 15 | #include "skia-shapes.h" 16 | 17 | static int element_spacing; 18 | static int num_x_elements; 19 | static int num_y_elements; 20 | 21 | int 22 | sk_setup_multi_shape(caskbench_context_t *ctx) 23 | { 24 | if (ctx->size <= 0) 25 | return 0; 26 | 27 | // Multi-shape setup 28 | element_spacing = sqrt( ((double)ctx->canvas_width * ctx->canvas_height) / ctx->size); 29 | num_x_elements = ctx->canvas_width / element_spacing; 30 | num_y_elements = ctx->canvas_height / element_spacing; 31 | 32 | return 1; 33 | } 34 | 35 | void 36 | sk_teardown_multi_shape(void) 37 | { 38 | } 39 | 40 | int 41 | sk_test_multi_shape(caskbench_context_t *ctx) 42 | { 43 | ctx->shape_defaults.radius = 0.9 * element_spacing / 2; 44 | ctx->shape_defaults.width = 2*ctx->shape_defaults.radius; 45 | ctx->shape_defaults.height = 2*ctx->shape_defaults.radius; 46 | 47 | for (int j=0; jshape_defaults, &shape); 51 | shape.x = i * element_spacing; 52 | shape.y = j * element_spacing; 53 | 54 | skiaDrawRandomizedShape(ctx, &shape); 55 | } 56 | } 57 | 58 | return 1; 59 | } 60 | 61 | /* 62 | Local Variables: 63 | mode:c++ 64 | c-file-style:"stroustrup" 65 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 66 | indent-tabs-mode:nil 67 | fill-column:99 68 | End: 69 | */ 70 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 71 | -------------------------------------------------------------------------------- /src/skia-tests/paint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include "caskbench.h" 13 | #include "caskbench_context.h" 14 | #include "skia-shapes.h" 15 | 16 | static SkRect r; 17 | 18 | int 19 | sk_setup_paint(caskbench_context_t *ctx) 20 | { 21 | return 1; 22 | } 23 | 24 | void 25 | sk_teardown_paint(void) 26 | { 27 | } 28 | 29 | int 30 | sk_test_paint(caskbench_context_t *ctx) 31 | { 32 | int i; 33 | for (i=0; isize; i++) { 34 | skiaRandomizePaintColor(ctx); 35 | ctx->skia_canvas->drawPaint(*ctx->skia_paint); 36 | } 37 | 38 | return 1; 39 | } 40 | 41 | /* 42 | Local Variables: 43 | mode:c++ 44 | c-file-style:"stroustrup" 45 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 46 | indent-tabs-mode:nil 47 | fill-column:99 48 | End: 49 | */ 50 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 51 | -------------------------------------------------------------------------------- /src/skia-tests/quadratic.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_quadratic(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_quadratic(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_quadratic(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | for (int i=0; isize; i++) { 42 | shape.x = (double)rnd()/RAND_MAX * w; 43 | shape.dx1 = (double)rnd()/RAND_MAX * w; 44 | shape.width = (double)rnd()/RAND_MAX * w - shape.x; 45 | shape.y = (double)rnd()/RAND_MAX * h; 46 | shape.dy1 = (double)rnd()/RAND_MAX * h; 47 | shape.height = (double)rnd()/RAND_MAX * h - shape.y; 48 | 49 | skiaRandomizePaintColor(ctx); 50 | skiaDrawQuadraticCurve(ctx, &shape); 51 | } 52 | 53 | return 1; 54 | } 55 | 56 | /* 57 | Local Variables: 58 | mode:c++ 59 | c-file-style:"stroustrup" 60 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 61 | indent-tabs-mode:nil 62 | fill-column:99 63 | End: 64 | */ 65 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 66 | -------------------------------------------------------------------------------- /src/skia-tests/radial-gradient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "caskbench.h" 17 | #include "caskbench_context.h" 18 | #include "skia-shapes.h" 19 | 20 | int 21 | sk_setup_radial_gradient(caskbench_context_t *ctx) 22 | { 23 | return 1; 24 | } 25 | 26 | void 27 | sk_teardown_radial_gradient(void) 28 | { 29 | } 30 | 31 | int 32 | sk_test_radial_gradient(caskbench_context_t *ctx) 33 | { 34 | int w = ctx->canvas_width; 35 | int h = ctx->canvas_height; 36 | int stops = 10; 37 | 38 | SkPoint pts[2]; 39 | pts[0].iset(20, 20); 40 | pts[1].iset(50, 50); 41 | SkScalar radii[2]; 42 | radii[0] = 20.0f; 43 | radii[1] = 70.0f; 44 | SkColor colors[10]; 45 | SkScalar pos[10]; 46 | 47 | for (int i = 0; i < stops; i++) { 48 | pos[i] = i / SkIntToScalar(stops - 1); 49 | colors[i] = skiaRandomColor(); 50 | } 51 | 52 | SkShader *shader = SkGradientShader::CreateTwoPointRadial(pts[0], radii[0], 53 | pts[1], radii[1], colors, pos, stops, 54 | SkShader::kClamp_TileMode); 55 | 56 | shapes_t shape; 57 | shape_copy(&ctx->shape_defaults, &shape); 58 | for (int i=0; isize; i++) { 59 | double x1 = (double)rnd()/RAND_MAX * w; 60 | double x2 = (double)rnd()/RAND_MAX * w; 61 | double y1 = (double)rnd()/RAND_MAX * h; 62 | double y2 = (double)rnd()/RAND_MAX * h; 63 | 64 | double xx = MIN(x1, x2); 65 | double yy = MIN(x1, x2); 66 | double ww = abs(x2 - x1); 67 | double hh = abs(y2 - y1); 68 | 69 | ctx->skia_canvas->save(); 70 | ctx->skia_canvas->translate(SkDoubleToScalar(xx), SkDoubleToScalar(yy)); 71 | ctx->skia_canvas->scale(SkDoubleToScalar(ww/100), SkDoubleToScalar(hh/100)); 72 | 73 | // transform(shape.width/100, 0, 0, shape.height/100, 0, 0) 74 | shape.x = 0; 75 | shape.y = 0; 76 | shape.width = 100; 77 | shape.height = 100; 78 | shape.fill_type = CB_FILL_RADIAL_GRADIENT; 79 | 80 | 81 | ctx->skia_paint->setStyle(SkPaint::kFill_Style); 82 | ctx->skia_paint->setShader(shader); 83 | 84 | skiaDrawRectangle(ctx, &shape); 85 | ctx->skia_canvas->restore(); 86 | 87 | } 88 | if (shader) 89 | shader->unref(); 90 | 91 | return 1; 92 | } 93 | 94 | /* 95 | Local Variables: 96 | mode:c++ 97 | c-file-style:"stroustrup" 98 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 99 | indent-tabs-mode:nil 100 | fill-column:99 101 | End: 102 | */ 103 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 104 | -------------------------------------------------------------------------------- /src/skia-tests/rect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | /* TODO: 20 | * - Specify with or without alpha 21 | * - With or without antialiasing? 22 | * - Stroke width should be via the shape defaults 23 | */ 24 | 25 | int 26 | sk_setup_rect(caskbench_context_t *ctx) 27 | { 28 | ctx->skia_paint->setAntiAlias(false); 29 | ctx->skia_paint->setStrokeWidth(1); 30 | 31 | return 1; 32 | } 33 | 34 | void 35 | sk_teardown_rect(void) 36 | { 37 | } 38 | 39 | int 40 | sk_test_rect(caskbench_context_t *ctx) 41 | { 42 | int w = ctx->canvas_width; 43 | int h = ctx->canvas_height; 44 | 45 | shapes_t shape; 46 | shape_copy(&ctx->shape_defaults, &shape); 47 | for (int i=0; isize; i++) { 48 | double x1 = (double)rnd()/RAND_MAX * w; 49 | double x2 = (double)rnd()/RAND_MAX * w; 50 | double y1 = (double)rnd()/RAND_MAX * h; 51 | double y2 = (double)rnd()/RAND_MAX * h; 52 | 53 | shape.x = MIN(x1, x2); 54 | shape.y = MIN(x1, x2); 55 | shape.width = abs(x2 - x1); 56 | shape.height = abs(y2 - y1); 57 | 58 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 59 | shape.fill_type = generate_random_fill_type(); 60 | } 61 | sk_set_fill_style(ctx, &shape); 62 | 63 | shape.shape_type = CB_SHAPE_RECTANGLE; 64 | skiaDrawRandomizedShape(ctx,&shape); 65 | } 66 | 67 | return 1; 68 | } 69 | 70 | /* 71 | Local Variables: 72 | mode:c++ 73 | c-file-style:"stroustrup" 74 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 75 | indent-tabs-mode:nil 76 | fill-column:99 77 | End: 78 | */ 79 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 80 | -------------------------------------------------------------------------------- /src/skia-tests/roundrect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_roundrect(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(true); 23 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 24 | return 1; 25 | } 26 | 27 | void 28 | sk_teardown_roundrect(void) 29 | { 30 | } 31 | 32 | int 33 | sk_test_roundrect(caskbench_context_t *ctx) 34 | { 35 | int i; 36 | double line_width, x, y, radius; 37 | 38 | for (i=0; isize; i++) { 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | 42 | skiaRandomizePaintColor(ctx); 43 | 44 | shape.x = trunc( (((double)ctx->canvas_width-20)*rnd())/RAND_MAX ) + 10; 45 | shape.y = trunc( (((double)ctx->canvas_height-20)*rnd())/RAND_MAX ) + 10; 46 | 47 | /* vary radius upto half of MIN(X,Y) */ 48 | shape.radius = (double)rnd()/RAND_MAX * 20; 49 | shape.width = 100; 50 | shape.height = 40; 51 | 52 | /* line_width cannot be more than twice of radius due to skia limitation - Issue #4 in skia https://github.com/Samsung/skia/issues/4 */ 53 | shape.stroke_width = (double)rnd()/RAND_MAX * (2*shape.radius); 54 | 55 | ctx->skia_paint->setStrokeWidth(shape.stroke_width); 56 | 57 | skiaDrawRoundedRectangle (ctx, &shape); 58 | } 59 | 60 | return 1; 61 | } 62 | 63 | /* 64 | Local Variables: 65 | mode:c++ 66 | c-file-style:"stroustrup" 67 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 68 | indent-tabs-mode:nil 69 | fill-column:99 70 | End: 71 | */ 72 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 73 | -------------------------------------------------------------------------------- /src/skia-tests/star.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_star(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_star(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_star(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | int counter = 1; // TODO 39 | 40 | shapes_t shape; 41 | shape_copy(&ctx->shape_defaults, &shape); 42 | for (int j = 0; jskia_canvas->save(); 46 | ctx->skia_canvas->translate(i, j); 47 | //ctx->skia_canvas->rotate(counter / 2000.0); 48 | ctx->skia_canvas->scale(0.2, 0.2); 49 | shape.x = 0; 50 | shape.y = 0; 51 | shape.radius = 40; 52 | if (ctx->shape_defaults.fill_type == CB_FILL_RANDOM) { 53 | shape.fill_type = generate_random_fill_type(); 54 | } 55 | sk_set_fill_style(ctx, &shape); 56 | 57 | shape.shape_type = CB_SHAPE_STAR; 58 | skiaDrawRandomizedShape(ctx,&shape); 59 | ctx->skia_canvas->restore(); 60 | } 61 | } 62 | 63 | return 1; 64 | } 65 | 66 | /* 67 | Local Variables: 68 | mode:c++ 69 | c-file-style:"stroustrup" 70 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 71 | indent-tabs-mode:nil 72 | fill-column:99 73 | End: 74 | */ 75 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 76 | -------------------------------------------------------------------------------- /src/skia-tests/text-glyphs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | // From http://www.atoker.com/blog/2008/09/06/skia-graphics-library-in-chrome-first-impressions/ 8 | #include 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "caskbench.h" 24 | #include "caskbench_context.h" 25 | #include "skia-shapes.h" 26 | 27 | // This test converts a text string to glyphs and displays it at various font sizes 28 | 29 | static int max_dim; 30 | static char rand_text_array[19][100]; 31 | 32 | void gen_skia_random(char *s, const int len) { 33 | static const char alphanum[] = 34 | "ABCD EFG HIJKL MNOPQ RSTUVW XYZ"; 35 | for (int i = 0; i < len; ++i) { 36 | s[i] = alphanum[rnd() % (sizeof(alphanum) - 1)]; 37 | } 38 | s[len] = 0; 39 | } 40 | 41 | int 42 | sk_setup_text_glyphs(caskbench_context_t *ctx) 43 | { 44 | max_dim = MIN(ctx->canvas_width, ctx->canvas_height)/2; 45 | ctx->skia_paint->setTextEncoding (SkPaint::kGlyphID_TextEncoding); 46 | return 1; 47 | } 48 | 49 | void 50 | sk_teardown_text_glyphs(void) 51 | { 52 | } 53 | 54 | static void getGlyphPositions(const SkPaint& paint, const uint16_t glyphs[], 55 | int count, SkScalar x, SkScalar y, SkPoint pos[]) { 56 | SkASSERT(SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()); 57 | 58 | SkAutoSTMalloc<128, SkScalar> widthStorage (count); 59 | SkScalar* widths = widthStorage.get(); 60 | paint.getTextWidths (glyphs, count * sizeof(uint16_t), widths); 61 | 62 | for (int i = 0; i < count; ++i) { 63 | pos[i].set(x, y); 64 | x += widths[i]; 65 | } 66 | } 67 | 68 | int 69 | sk_test_text_glyphs(caskbench_context_t *ctx) 70 | { 71 | double font_size = 18; 72 | int ypos = 15, xpos = 0; 73 | double font_factor = 0.5; 74 | SkPaint dummy_paint; 75 | ctx->skia_canvas->drawColor(SK_ColorBLACK); 76 | for (int i = 0; i < ctx->size; i++) 77 | { 78 | ctx->skia_paint->setTextSize (SkIntToScalar (font_size)); 79 | skiaRandomizePaintColor(ctx); 80 | 81 | SkAutoSTMalloc<128, uint16_t> glyphStorage (font_size); 82 | uint16_t* glyphs = glyphStorage.get(); 83 | 84 | char text[(int)font_size]; 85 | gen_skia_random (text,font_size); 86 | 87 | // ctx->skia_paint gives wrong glyphCount and draws nothing, as text encoding is enabled. Using a dummy paint variable as of now. 88 | int glyphCount = dummy_paint.textToGlyphs (text, font_size, glyphs); 89 | ctx->skia_canvas->drawText (glyphs, glyphCount * sizeof(uint16_t), xpos,ypos, *(ctx->skia_paint)); 90 | 91 | font_size = font_size+font_factor; 92 | ypos += (font_size/2); 93 | if (font_size >= 36) 94 | font_size = 36; 95 | if (ypos > ctx->canvas_height/2) 96 | font_factor = -0.5; 97 | if (font_size < 18) 98 | font_size = 18; 99 | } 100 | return 1; 101 | } 102 | 103 | /* 104 | Local Variables: 105 | mode:c++ 106 | c-file-style:"stroustrup" 107 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 108 | indent-tabs-mode:nil 109 | fill-column:99 110 | End: 111 | */ 112 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 113 | -------------------------------------------------------------------------------- /src/skia-tests/text.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "caskbench.h" 23 | #include "caskbench_context.h" 24 | #include "skia-shapes.h" 25 | 26 | // This tests basic (non-glyph) text functionality 27 | 28 | int 29 | sk_setup_text(caskbench_context_t *ctx) 30 | { 31 | SkTypeface *style = SkTypeface::CreateFromName("Serif", SkTypeface::kBold); 32 | 33 | ctx->skia_paint->setTypeface(style); 34 | ctx->skia_paint->setAntiAlias(false); 35 | ctx->skia_paint->setStyle(SkPaint::kFill_Style); 36 | ctx->skia_paint->setTextSize(20.0f); 37 | 38 | style->unref(); 39 | 40 | return 1; 41 | } 42 | 43 | void 44 | sk_teardown_text(void) 45 | { 46 | } 47 | 48 | int 49 | sk_test_text(caskbench_context_t *ctx) 50 | { 51 | char text[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 52 | size_t byteLength = strlen(text) * sizeof(char); 53 | double tw = SkScalarToDouble(ctx->skia_paint->measureText(text, byteLength)); 54 | 55 | double w = (double)ctx->canvas_width; 56 | double h = (double)ctx->canvas_height; 57 | double off = abs (w - tw); 58 | 59 | ctx->skia_canvas->drawColor(SK_ColorBLACK); 60 | 61 | for (int i = 0; i < ctx->size; i++) 62 | { 63 | double x = drnd48() * off; 64 | double y = drnd48() * h; 65 | 66 | skiaRandomizePaintColor(ctx); 67 | 68 | ctx->skia_canvas->drawText(text, byteLength, SkDoubleToScalar(x), 69 | SkDoubleToScalar(y), *(ctx->skia_paint)); 70 | } 71 | return 1; 72 | } 73 | 74 | /* 75 | Local Variables: 76 | mode:c++ 77 | c-file-style:"stroustrup" 78 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 79 | indent-tabs-mode:nil 80 | fill-column:99 81 | End: 82 | */ 83 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 84 | -------------------------------------------------------------------------------- /src/skia-tests/transform.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_transform(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_transform(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_transform(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | SkScalar rotation_delta(0.02*180/M_PI); 39 | 40 | ctx->skia_canvas->save(); 41 | for (int nn=0; nnsize; nn++) { 42 | for (int i=0; iskia_canvas->drawPath(p1, *(ctx->skia_paint)); 48 | } 49 | for (int j=0; jskia_canvas->drawPath(p2, *(ctx->skia_paint)); 55 | } 56 | ctx->skia_canvas->translate(w/2.0, h/2.0); 57 | ctx->skia_canvas->rotate(rotation_delta); 58 | ctx->skia_canvas->scale(1.004, 0.996); 59 | ctx->skia_canvas->translate(-w/2.0, -h/2.0); 60 | } 61 | ctx->skia_canvas->restore(); 62 | 63 | return 1; 64 | } 65 | 66 | /* 67 | Local Variables: 68 | mode:c++ 69 | c-file-style:"stroustrup" 70 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 71 | indent-tabs-mode:nil 72 | fill-column:99 73 | End: 74 | */ 75 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 76 | -------------------------------------------------------------------------------- /src/skia-tests/vline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include "caskbench.h" 16 | #include "caskbench_context.h" 17 | #include "skia-shapes.h" 18 | 19 | int 20 | sk_setup_vline(caskbench_context_t *ctx) 21 | { 22 | ctx->skia_paint->setAntiAlias(false); 23 | ctx->skia_paint->setStrokeWidth(1); 24 | ctx->skia_paint->setStyle(SkPaint::kStroke_Style); 25 | return 1; 26 | } 27 | 28 | void 29 | sk_teardown_vline(void) 30 | { 31 | } 32 | 33 | int 34 | sk_test_vline(caskbench_context_t *ctx) 35 | { 36 | int w = ctx->canvas_width; 37 | int h = ctx->canvas_height; 38 | 39 | shapes_t shape; 40 | shape_copy(&ctx->shape_defaults, &shape); 41 | for (int i=0; isize; i++) { 42 | double x = (double)rnd()/RAND_MAX * w; 43 | double y1 = (double)rnd()/RAND_MAX * h; 44 | double y2 = (double)rnd()/RAND_MAX * h; 45 | 46 | shape.x = x; 47 | shape.y = y1; 48 | shape.width = 0; 49 | shape.height = y1 - y2; 50 | 51 | skiaRandomizePaintColor(ctx); 52 | skiaDrawLine(ctx, &shape); 53 | } 54 | 55 | return 1; 56 | } 57 | 58 | /* 59 | Local Variables: 60 | mode:c++ 61 | c-file-style:"stroustrup" 62 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 63 | indent-tabs-mode:nil 64 | fill-column:99 65 | End: 66 | */ 67 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 68 | -------------------------------------------------------------------------------- /src/skia-util.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "caskbench.h" 17 | #include "caskbench_context.h" 18 | 19 | void 20 | context_clear_skia (caskbench_context_t *context) 21 | { 22 | context->skia_canvas->drawColor(SK_ColorBLACK); 23 | } 24 | 25 | void 26 | write_image_file_skia (const char *fname, caskbench_context_t *context) 27 | { 28 | SkBitmap bitmap; 29 | void * data; 30 | SkString path(fname); 31 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 32 | context->canvas_width, context->canvas_height); 33 | SkImageInfo info = SkImageInfo::Make(context->canvas_width, context->canvas_height, 34 | kBGRA_8888_SkColorType, 35 | kPremul_SkAlphaType); 36 | bitmap.allocPixels(info); 37 | context->skia_canvas->flush(); 38 | if (!context->skia_canvas->readPixels(&bitmap, 0, 0)) { 39 | warnx("Could not read pixels from skia device\n"); 40 | return; 41 | } 42 | SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG_Type, 0); 43 | } 44 | 45 | /* 46 | Local Variables: 47 | mode:c++ 48 | c-file-style:"stroustrup" 49 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 50 | indent-tabs-mode:nil 51 | fill-column:99 52 | End: 53 | */ 54 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 55 | -------------------------------------------------------------------------------- /src/tests.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 © Samsung Research America, Silicon Valley 3 | * 4 | * Use of this source code is governed by the 3-Clause BSD license 5 | * specified in the COPYING file included with this source code. 6 | */ 7 | #ifndef __TESTS_H__ 8 | #define __TESTS_H__ 9 | 10 | #include "forward.h" 11 | 12 | typedef struct _caskbench_perf_test { 13 | const char *name; 14 | int (*setup)(struct _caskbench_context*); 15 | void (*teardown)(void); 16 | int (*test_case)(struct _caskbench_context*); 17 | void (*write_image)(const char *, struct _caskbench_context*); 18 | void (*context_setup)(struct _caskbench_context*, const device_config_t& config); 19 | void (*context_destroy)(struct _caskbench_context*); 20 | void (*context_update)(struct _caskbench_context*); 21 | void (*context_clear)(struct _caskbench_context*); 22 | } caskbench_perf_test_t; 23 | 24 | extern caskbench_perf_test_t perf_tests[]; 25 | extern const int num_perf_tests; 26 | 27 | void write_image_file_cairo(const char *fname, struct _caskbench_context *context); 28 | void write_image_file_skia(const char *fname, struct _caskbench_context *context); 29 | 30 | void context_setup_cairo(struct _caskbench_context *context, const device_config_t& config); 31 | void context_setup_skia(struct _caskbench_context *context, const device_config_t& config); 32 | 33 | void context_destroy_cairo(struct _caskbench_context *context); 34 | void context_destroy_skia(struct _caskbench_context *context); 35 | 36 | void context_update_cairo(struct _caskbench_context *context); 37 | void context_update_skia(struct _caskbench_context *context); 38 | 39 | void context_clear_cairo(struct _caskbench_context *context); 40 | void context_clear_skia(struct _caskbench_context *context); 41 | #endif // __TESTS_H__ 42 | /* 43 | Local Variables: 44 | mode:c++ 45 | c-file-style:"stroustrup" 46 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 47 | indent-tabs-mode:nil 48 | fill-column:99 49 | End: 50 | */ 51 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 52 | -------------------------------------------------------------------------------- /utils/compare_runs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import json 5 | from os.path import (basename, dirname) 6 | 7 | run_ids = [] 8 | data = {} 9 | for json_file in sys.argv[1:]: 10 | with open(json_file) as file: 11 | run_id = basename(dirname(json_file)) 12 | run_ids.append(run_id) 13 | data[run_id] = json.load(file) 14 | 15 | results = {} 16 | for run_id in run_ids: 17 | for item in data[run_id]: 18 | lib = item[u'test case'].split('-')[0] 19 | testcase = item[u'test case'].split('-')[1] 20 | avg_time = item[u'average run time (s)'] 21 | if testcase not in results.keys(): 22 | results[testcase] = {} 23 | if run_id not in results[testcase].keys(): 24 | results[testcase][run_id] = {} 25 | results[testcase][run_id][lib] = avg_time 26 | 27 | # First header 28 | print("%-12s " %('')), 29 | for run_id in run_ids: 30 | label = run_id.split('-')[1].upper() 31 | print(" ==== %-16s ==== " %(label)), 32 | print("\n"), 33 | 34 | # Second header 35 | print("%-12s " % 'test case'), 36 | for run_id in run_ids: 37 | for lib in ['cairo', 'skia']: 38 | print(" %-6s " %(lib)), 39 | print(" %8s %s" %('ca:sk', ' ')), 40 | if len(run_ids) == 2: 41 | print(" %8s %8s" %('ca:ca', 'sk:sk')), 42 | print("\n"), 43 | 44 | testcases = results.keys() 45 | testcases.sort() 46 | for testcase in testcases: 47 | print("%-12s " %(testcase)), 48 | for run_id in run_ids: 49 | cairo_value = results[testcase][run_id]['cairo'] 50 | skia_value = results[testcase][run_id]['skia'] 51 | improvement = 100*(cairo_value - skia_value)/cairo_value 52 | print(" %8f %8f %7.1f%% " %(cairo_value, skia_value, improvement)), 53 | 54 | if len(run_ids) == 2: 55 | ca0 = results[testcase][run_ids[0]]['cairo'] 56 | ca1 = results[testcase][run_ids[1]]['cairo'] 57 | sk0 = results[testcase][run_ids[0]]['skia'] 58 | sk1 = results[testcase][run_ids[1]]['skia'] 59 | if ca0 == 0: 60 | ca_ca_improvement = 0 61 | else: 62 | ca_ca_improvement = 100*(ca0 - ca1)/ca0 63 | if sk0 == 0: 64 | sk_sk_improvement = 0 65 | else: 66 | sk_sk_improvement = 100*(sk0 - sk1)/sk0 67 | print(" %7.1f%% %7.1f%%" %(ca_ca_improvement, sk_sk_improvement)), 68 | 69 | print("\n"), 70 | 71 | -------------------------------------------------------------------------------- /utils/flashcanvas: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # This script intends to operate caskbench in a manner that 4 | # will replicate the results of canvas_perf.js, but in C++. 5 | # 6 | # ref: 7 | # http://flashcanvas.net/examples/dl.dropbox.com/u/1865210/mindcat/canvas_perf.html 8 | 9 | from __future__ import absolute_import, print_function, unicode_literals 10 | 11 | from exceptions import Exception 12 | from subprocess import (Popen, PIPE) 13 | import json 14 | 15 | CASKBENCH = 'src/caskbench' 16 | 17 | perfdefs = [ 18 | [ "hline", 1000, 30, ["hline"] ], 19 | [ "vline", 1000, 15, ["vline"] ], 20 | [ "line", 1000, 6, ["line"] ], 21 | [ "rect", 1000, 5, ["rect", "-f", "none"] ], 22 | [ "fill_rect", 500, 5, ["rect", "-f", "solid"] ], 23 | [ "lines", 1000, 8, ["multi_line"] ], 24 | [ "arc", 1000, 4, ["circle", "-f", "none"] ], 25 | [ "fill_arc", 1000, 7, ["circle", "-f", "solid"] ], 26 | [ "bezier", 1000, 3, ["cubic"] ], 27 | [ "fill_bezier", 1000, 4, ["cubic", "-f", "solid"] ], 28 | [ "quad", 1000, 4, ["quadratic"] ], 29 | [ "curves", 50, 5, ["curves", "-f", "none"] ], 30 | [ "fill_curves", 50, 8, ["curves", "-f", "solid"] ], 31 | [ "stroke_star", 1000, 7, ["star", "-f", "none"] ], 32 | [ "fill_star", 1000, 12, ["star", "-f", "solid"] ], 33 | [ "transform", 10, 0.2, ["transform"] ], 34 | [ "image", 100, 0.3, ["image"] ], 35 | [ "image_scale", 100, 0.8, ["image_scale"] ], 36 | [ "image_rotate", 15, 0.3, ["image_rotate"] ], 37 | [ "linear_gradient", 100, 2, ["linear_gradient"] ], 38 | [ "radial_gradient", 100, 0.3, ["radial_gradient"] ], 39 | [ "text", 100, 0.6, ["text"] ], 40 | [ "clip", 100, 0.8, ["clip"] ] 41 | ] 42 | 43 | class ReturnCode(Exception): 44 | def __init__(self, code, errors=None): 45 | self.code = code 46 | if type(errors) in (list, tuple): 47 | self.errors = errors 48 | else: 49 | self.errors = [errors] 50 | 51 | def __str__(self): 52 | text = '\n'.join(self.errors) 53 | return "%s returned error code %d" %(text, self.code) 54 | 55 | def execute(command): 56 | p = Popen(command, shell=False, stdout=PIPE, stderr=PIPE) 57 | output = p.stdout.read() 58 | if p.returncode: 59 | dbg("Error (%d) encountered in execution" %(p.returncode)) 60 | raise ReturnCode(p.returncode, p.stderr.readlines()) 61 | return output 62 | 63 | 64 | results = [] 65 | iterations = 100 66 | for testcase in perfdefs: 67 | cmd = [ CASKBENCH, 68 | '-D', 'skia', 69 | '-w', '480', 70 | '-h', '480', 71 | '-i', str(iterations), 72 | '-s', str(testcase[1]), 73 | '-j', 74 | '-o', '/tmp/output.json', 75 | '-t', 'egl', 76 | '--deferred-rendering', 77 | ] 78 | 79 | cmd += testcase[3] 80 | 81 | print(' '.join(cmd)) 82 | json_output = execute(cmd) 83 | print(json_output) 84 | 85 | with open('/tmp/output.json') as file: 86 | result = json.load(file)[0] 87 | 88 | value = testcase[1] / (result["average run time (s)"]*1000) 89 | ratio = value / testcase[2] 90 | 91 | results.append({ 92 | 'testcase': testcase[0], 93 | 'ratio': ratio 94 | }) 95 | 96 | # Calculate the score 97 | total = 0 98 | for result in results: 99 | print("%s: %3.2f" %(result['testcase'], result['ratio'])) 100 | total += 1.0 / result['ratio'] 101 | 102 | if total > 0: 103 | score = (len(perfdefs) / total) 104 | print("Total Score: %3.2f" %(score)) 105 | -------------------------------------------------------------------------------- /utils/json2csv: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | import csv 5 | import json 6 | 7 | json_file = sys.argv[1] 8 | if len(sys.argv) > 2: 9 | csv_file = sys.argv[2] 10 | else: 11 | csv_file = "results.csv" 12 | 13 | with open(json_file) as file: 14 | data = json.load(file) 15 | 16 | with open(csv_file, "w") as file: 17 | csv_file = csv.writer(file) 18 | for item in data: 19 | csv_file.writerow([item['test case'], item['size'], 20 | item['iterations'], item['minimum run time (s)'], 21 | item['average run time (s)'], item['maximum run time (s)'], 22 | item['median run time (s)'], item['standard deviation of run time (s)'], 23 | item['avg frames per second (fps)']]) 24 | -------------------------------------------------------------------------------- /utils/make_index: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat < 5 | 6 | 42 | 43 | 44 | 45 |

Cairo vs. Skia

46 | 47 | 48 | 49 | EOF 50 | 51 | for test in src/skia-tests/*; do 52 | name=$(basename ${test%.cpp}) 53 | cat < 55 | 56 | 57 | 58 | 59 | 60 | EOF 61 | 62 | done 63 | 64 | cat <
${name}
66 | 67 | 68 | 69 | EOF 70 | -------------------------------------------------------------------------------- /utils/mandel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ezhangle/caskbench/dc28549f493526a4eb5ebf2300097fefc9e14868/utils/mandel.png -------------------------------------------------------------------------------- /utils/run_benchmark: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | iterations=100 4 | size=256 5 | 6 | export DISPLAY=:0 7 | 8 | which hostname > /dev/null 9 | if [ $? = 0 ]; then 10 | host=$(hostname -s) 11 | else 12 | host=$HOSTNAME 13 | fi 14 | 15 | if [ -z "$host" ]; then 16 | echo "Error: Could not determine hostname" 17 | exit 1 18 | fi 19 | 20 | # This script assumes you've built caskbench in a sub-directory 21 | # named "build-HOST". It invokes the executable from that build 22 | # tree, and stores the results in a directories named 23 | # results-NNN/HOST-SURFACE. 24 | CASKBENCH="build-${host}/src/caskbench" 25 | if [ ! -e ${CASKBENCH} ]; then 26 | which caskbench > /dev/null 27 | if [ $? = 0 ]; then 28 | CASKBENCH=caskbench 29 | fi 30 | fi 31 | if [ -z "$CASKBENCH" ]; then 32 | echo "Could not locate caskbench executable" 33 | exit 1 34 | fi 35 | 36 | run_caskbench() { 37 | out=$1 38 | surface=$2 39 | options=$3 40 | 41 | outjson="${out}/results.json" 42 | outtxt="${out}/results.txt" 43 | outcsv="${out}/results.csv" 44 | 45 | rm -f cairo*.png skia*.png 46 | mkdir -p ${out} 47 | if [ $? != 0 ]; then 48 | echo "Error creating ${out}: $?" 49 | return 1 50 | fi 51 | cp ./index.html ${out}/ 52 | echo "== ${surface^^} ==" | tee ${outtxt} 53 | ${CASKBENCH} -t ${surface} -i ${iterations} -s ${size} -o ${outjson} \ 54 | --enable-output-images ${options} | tee -a ${outtxt} 55 | if [ $? == 0 ]; then 56 | mv -f cairo*.png skia*.png ${out}/ 57 | fi 58 | echo | tee -a ${outtxt} 59 | 60 | # Add csv version of data 61 | if [ ! -e ${outjson} ]; then 62 | return 1 63 | fi 64 | ./utils/json2csv ${outjson} ${outcsv} 65 | return 0 66 | } 67 | 68 | id=0 69 | results_dir=. 70 | today=$(date +%Y%m%d) 71 | while [ -d "${results_dir}" ]; do 72 | id=$(( id + 1 )) 73 | results_dir=$(printf "results-${today}-%02d" $id) 74 | done 75 | 76 | surfaces=$(${CASKBENCH} -l) 77 | #echo "MSAA (--enable-egl-sample-buffers)" >> ${results_dir}/comparison.txt 78 | export CAIRO_GL_COMPOSITOR=msaa 79 | for surface in ${surfaces}; do 80 | run_caskbench "${results_dir}/${host}-${surface}" "${surface}" 81 | done 82 | ./utils/compare_runs "${results_dir}/${host}-image/results.json" "${results_dir}/${host}-egl/results.json" \ 83 | >> ${results_dir}/comparison.txt 84 | echo >> ${results_dir}/comparison.txt 85 | 86 | -------------------------------------------------------------------------------- /utils/system_description.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export DISPLAY=:0 4 | 5 | . /etc/lsb-release 6 | 7 | cpu=$(grep ^model\ name /proc/cpuinfo | head -n1 | cut -d: -f2) 8 | xserver_version=$(/usr/bin/Xorg -version |& grep ^xorg-server | cut -d' ' -f2) 9 | mesa_version=$(glxinfo | grep "OpenGL version") 10 | xpci=$(xpci) 11 | kernel=$(uname -r) 12 | platform=$(uname -po) 13 | 14 | cat <