1/* 2 Copyright (C) 2009-2012 Samsung Electronics 3 Copyright (C) 2009-2010 ProFUSION embedded systems 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19*/ 20 21/** 22 * @file ewk_paint_context_private.h 23 * @brief Describes the paint context API. 24 */ 25 26#ifndef ewk_paint_context_private_h 27#define ewk_paint_context_private_h 28 29#include "FrameView.h" 30#include "GraphicsContext.h" 31#include "RefPtrCairo.h" 32#include <Evas.h> 33#include <cairo.h> 34 35/// Creates a type name for @a _Ewk_Paint_Context. 36typedef struct _Ewk_Paint_Context Ewk_Paint_Context; 37 38/** 39 * @brief Structure that keeps the paint context. 40 * 41 * @internal 42 * 43 * @note This is not for general use but just for subclasses that want 44 * to define their own backing store. 45 */ 46struct _Ewk_Paint_Context { 47 OwnPtr<WebCore::GraphicsContext> graphicContext; 48 RefPtr<cairo_t> cairo; 49 RefPtr<cairo_surface_t> surface; /**< surface used to create cairo object */ 50 Evas_Object* image; /**< image used to create cairo surface */ 51 unsigned char* pixels; /**< pixels form image */ 52}; 53 54/** 55 * @internal 56 * Creates a new paint context using a cairo as output. 57 * 58 * @param cairo context to use as paint destination, a new 59 * reference is taken, so it's safe to call @c cairo_destroy() 60 * after this function returns. 61 * 62 * @return a newly allocated instance of @c Ewk_Paint_Context on success, 63 * or @c 0 on failure 64 * 65 * @note This is not for general use but just for subclasses that want 66 * to define their own backing store. 67 */ 68Ewk_Paint_Context* ewk_paint_context_new(cairo_t* cairo); 69 70/** 71 * @internal 72 * Creates a new paint context using an image as output. 73 * 74 * @param image to use as paint destination 75 * 76 * @return a newly allocated instance of @c Ewk_Paint_Context on success, 77 * or @c 0 on failure 78 * 79 * @note This is not for general use but just for subclasses that want 80 * to define their own backing store. 81 */ 82Ewk_Paint_Context* ewk_paint_context_from_image_new(Evas_Object* image); 83 84/** 85 * @internal 86 * Creates a new paint context using an image as output. 87 * 88 * @param pixel pointer to pixel buffer 89 * @param width size of pixel buffer 90 * @param height size of pixel buffer 91 * @param colorSpace Evas_Colorspace of pixel buffer 92 * 93 * @return a newly allocated instance of @c Ewk_Paint_Context on success, 94 * or @c 0 on failure 95 * 96 * @note This is not for general use but just for subclasses that want 97 * to define their own backing store. 98 */ 99Ewk_Paint_Context* ewk_paint_context_from_image_data_new(uint8_t* pixels, int width, int height, int colorSpace); 100 101/** 102 * @internal 103 * Destroys the previously created the paint context. 104 * 105 * @param context the paint context to destroy, must @b not be @c 0 106 * 107 * @note This is not for general use but just for subclasses that want 108 * to define their own backing store. 109 */ 110void ewk_paint_context_free(Ewk_Paint_Context* context); 111 112/** 113 * @internal 114 * Saves (push to stack) the paint context status. 115 * 116 * @param context the paint context to save, must @b not be @c 0 117 * 118 * @see ewk_paint_context_restore() 119 * 120 * @note This is not for general use but just for subclasses that want 121 * to define their own backing store. 122 */ 123void ewk_paint_context_save(Ewk_Paint_Context* context); 124 125/** 126 * @internal 127 * Restores (pop from stack) the paint context status. 128 * 129 * @param context the paint context to restore, must @b not be @c 0 130 * 131 * @see ewk_paint_context_save() 132 * 133 * @note This is not for general use but just for subclasses that want 134 * to define their own backing store. 135 */ 136void ewk_paint_context_restore(Ewk_Paint_Context* context); 137 138/** 139 * @internal 140 * Clips the paint context drawings to the given area. 141 * 142 * @param context the paint context to clip, must @b not be @c 0 143 * @param area clip area to use, must @b not be @c 0 144 * 145 * @see ewk_paint_context_save() 146 * @see ewk_paint_context_restore() 147 * 148 * @note This is not for general use but just for subclasses that want 149 * to define their own backing store. 150 */ 151void ewk_paint_context_clip(Ewk_Paint_Context* context, const Eina_Rectangle* area); 152 153/** 154 * @internal 155 * Scales the contents by the given factors. 156 * 157 * This function applies a scaling transformation using Cairo. 158 * 159 * @param context the paint context to scale, must @b not be @c 0 160 * @param scale_x the scale factor for the X dimension 161 * @param scale_y the scale factor for the Y dimension 162 */ 163void ewk_paint_context_scale(Ewk_Paint_Context* context, float scale_x, float scale_y); 164 165/** 166 * @internal 167 * Performs a translation of the origin coordinates. 168 * 169 * This function moves the origin coordinates by @a x and @a y pixels. 170 * 171 * @param context the paint context to translate, must @b not be @c 0 172 * @param x amount of pixels to translate in the X dimension 173 * @param y amount of pixels to translate in the Y dimension 174 */ 175void ewk_paint_context_translate(Ewk_Paint_Context* context, float x, float y); 176 177/** 178 * @internal 179 * Paints the context using given area. 180 * 181 * @param context the paint context to paint, must @b not be @c 0 182 * @param view the view to paint 183 * @param area the paint area to use, coordinates are relative to current viewport, 184 * thus "scrolled", must @b not be @c 0 185 * 186 * @note One may use cairo functions on the cairo context to 187 * translate, scale or any modification that may fit his desires. 188 * 189 * @see ewk_paint_context_clip() 190 * @see ewk_paint_context_paint_contents() 191 * 192 * @note This is not for general use but just for subclasses that want 193 * to define their own backing store. 194 */ 195void ewk_paint_context_paint(Ewk_Paint_Context* context, WebCore::FrameView* view, const Eina_Rectangle* area); 196 197/** 198 * @internal 199 * Paints just contents using context using given area. 200 * 201 * Unlike ewk_paint_context_paint(), this function paint just 202 * bare contents and ignores any scrolling, scrollbars and extras. It 203 * will walk the rendering tree and paint contents inside the given 204 * area to the cairo context specified in @a context. 205 * 206 * @param context the paint context to paint, must @b not be @c 0. 207 * @param view the view to paint 208 * @param area the paint area to use, coordinates are absolute to page, must @b not be @c 0 209 * 210 * @note One may use cairo functions on the cairo context to 211 * translate, scale or any modification that may fit his desires. 212 * 213 * @see ewk_paint_context_clip() 214 * @see ewk_paint_context_paint() 215 * 216 * @note This is not for general use but just for subclasses that want 217 * to define their own backing store. 218 */ 219void ewk_paint_context_paint_contents(Ewk_Paint_Context* context, WebCore::FrameView* view, const Eina_Rectangle* area); 220 221#endif // ewk_paint_context_private_h 222