1544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin/************************************************************************** 2544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * 3544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * Copyright 2009 VMware, Inc. All Rights Reserved. 4544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * 5544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * Permission is hereby granted, free of charge, to any person obtaining a 6544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * copy of this software and associated documentation files (the 7544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * "Software"), to deal in the Software without restriction, including 8544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * without limitation the rights to use, copy, modify, merge, publish, 9544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * distribute, sub license, and/or sell copies of the Software, and to 10544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * permit persons to whom the Software is furnished to do so, subject to 11544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * the following conditions: 12544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * 13544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * The above copyright notice and this permission notice (including the 14544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * next paragraph) shall be included in all copies or substantial portions 15544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * of the Software. 16544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * 17544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 21544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin * 25544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin **************************************************************************/ 26544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 27544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "image.h" 28544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 29544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "vg_translate.h" 30544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "vg_context.h" 31544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "matrix.h" 32544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "renderer.h" 33544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "util_array.h" 34544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "api_consts.h" 35544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "shader.h" 36544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 37544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "pipe/p_context.h" 38544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "pipe/p_screen.h" 3928486880ca3ec39419ccee0cb1a3bedc9ef7117cJosé Fonseca#include "util/u_inlines.h" 406df42d80234d13676fc3207cf44f0e371e3372b5Michal Krol#include "util/u_format.h" 41544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "util/u_tile.h" 42544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "util/u_memory.h" 43544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#include "util/u_math.h" 44e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger#include "util/u_sampler.h" 454c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger#include "util/u_surface.h" 46544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 47544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinstatic enum pipe_format vg_format_to_pipe(VGImageFormat format) 48544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 49544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin switch(format) { 50544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_sRGB_565: 51b306308757c0ce3cf47a50bac12bb39f212ca6b2José Fonseca return PIPE_FORMAT_B5G6R5_UNORM; 52544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_sRGBA_5551: 53b306308757c0ce3cf47a50bac12bb39f212ca6b2José Fonseca return PIPE_FORMAT_B5G5R5A1_UNORM; 54544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_sRGBA_4444: 55b306308757c0ce3cf47a50bac12bb39f212ca6b2José Fonseca return PIPE_FORMAT_B4G4R4A4_UNORM; 56544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_sL_8: 57544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_lL_8: 58544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_FORMAT_L8_UNORM; 59544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_BW_1: 60b306308757c0ce3cf47a50bac12bb39f212ca6b2José Fonseca return PIPE_FORMAT_B8G8R8A8_UNORM; 61544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_A_8: 62544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_FORMAT_A8_UNORM; 63544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#ifdef OPENVG_VERSION_1_1 64544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_A_1: 65544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_A_4: 66544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_FORMAT_A8_UNORM; 67544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#endif 68544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin default: 69b306308757c0ce3cf47a50bac12bb39f212ca6b2José Fonseca return PIPE_FORMAT_B8G8R8A8_UNORM; 70544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 71544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 72544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 73544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinstatic INLINE void vg_sync_size(VGfloat *src_loc, VGfloat *dst_loc) 74544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 75544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[2] = MIN2(src_loc[2], dst_loc[2]); 76544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[3] = MIN2(src_loc[3], dst_loc[3]); 77544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[2] = src_loc[2]; 78544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[3] = src_loc[3]; 79544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 80544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 8133ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wustatic void vg_get_copy_coords(VGfloat *src_loc, 8233ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu VGfloat src_width, VGfloat src_height, 8333ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu VGfloat *dst_loc, 8433ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu VGfloat dst_width, VGfloat dst_height) 85544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 86544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat dst_bounds[4], src_bounds[4]; 87544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat src_shift[4], dst_shift[4], shift[4]; 88544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 89544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_bounds[0] = 0.f; 90544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_bounds[1] = 0.f; 9133ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_bounds[2] = dst_width; 9233ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_bounds[3] = dst_height; 93544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 94544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_bounds[0] = 0.f; 95544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_bounds[1] = 0.f; 9633ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_bounds[2] = src_width; 9733ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_bounds[3] = src_height; 98544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 99544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_bound_rect(src_loc, src_bounds, src_shift); 100544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_bound_rect(dst_loc, dst_bounds, dst_shift); 101544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shift[0] = src_shift[0] - dst_shift[0]; 102544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shift[1] = src_shift[1] - dst_shift[1]; 103544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 104544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (shift[0] < 0) 105544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_shift_rectx(src_loc, src_bounds, -shift[0]); 106544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin else 107544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_shift_rectx(dst_loc, dst_bounds, shift[0]); 108544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 109544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (shift[1] < 0) 110544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_shift_recty(src_loc, src_bounds, -shift[1]); 111544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin else 112544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_shift_recty(dst_loc, dst_bounds, shift[1]); 113544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 114544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_sync_size(src_loc, dst_loc); 11533ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu} 11633ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu 11733ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wustatic void vg_copy_texture(struct vg_context *ctx, 11833ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu struct pipe_resource *dst, VGint dx, VGint dy, 11933ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu struct pipe_sampler_view *src, VGint sx, VGint sy, 12033ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu VGint width, VGint height) 12133ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu{ 12233ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu VGfloat dst_loc[4], src_loc[4]; 12333ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu 12433ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc[0] = dx; 12533ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc[1] = dy; 12633ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc[2] = width; 12733ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc[3] = height; 12833ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu 12933ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_loc[0] = sx; 13033ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_loc[1] = sy; 13133ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_loc[2] = width; 13233ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu src_loc[3] = height; 13333ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu 13433ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu vg_get_copy_coords(src_loc, src->texture->width0, src->texture->height0, 13533ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc, dst->width0, dst->height0); 136544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 137544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (src_loc[2] >= 0 && src_loc[3] >= 0 && 138544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[2] >= 0 && dst_loc[3] >= 0) { 1394c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger struct pipe_surface *surf, surf_tmpl; 14020ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu 14120ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu /* get the destination surface */ 1424c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger u_surface_default_template(&surf_tmpl, dst, PIPE_BIND_RENDER_TARGET); 1434c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger surf = ctx->pipe->create_surface(ctx->pipe, dst, &surf_tmpl); 14420ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu if (surf && renderer_copy_begin(ctx->renderer, surf, VG_TRUE, src)) { 14520ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu renderer_copy(ctx->renderer, 14620ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu dst_loc[0], dst_loc[1], dst_loc[2], dst_loc[3], 14720ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu src_loc[0], src_loc[1], src_loc[2], src_loc[3]); 14820ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu renderer_copy_end(ctx->renderer); 14920ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu } 15020ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu 15120ce148c305200c760f34d2098d92bc77cb6deeeChia-I Wu pipe_surface_reference(&surf, NULL); 152544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 153544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 154544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 155544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid vg_copy_surface(struct vg_context *ctx, 156544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_surface *dst, VGint dx, VGint dy, 157544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_surface *src, VGint sx, VGint sy, 158544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 159544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 160544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat dst_loc[4], src_loc[4]; 161544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 162544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[0] = dx; 163544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[1] = dy; 164544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[2] = width; 165544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[3] = height; 166544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 167544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[0] = sx; 168544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[1] = sy; 169544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[2] = width; 170544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[3] = height; 171544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 17233ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu vg_get_copy_coords(src_loc, src->width, src->height, 17333ca973e7a6036566aa7363681419a58a30ab0f3Chia-I Wu dst_loc, dst->width, dst->height); 174544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 175544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (src_loc[2] > 0 && src_loc[3] > 0 && 176544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[2] > 0 && dst_loc[3] > 0) { 177544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (src == dst) 178544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin renderer_copy_surface(ctx->renderer, 179544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src, 180544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[0], 181544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src->height - (src_loc[1] + src_loc[3]), 182544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[0] + src_loc[2], 183544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src->height - src_loc[1], 184544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst, 185544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[0], 186544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst->height - (dst_loc[1] + dst_loc[3]), 187544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[0] + dst_loc[2], 188544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst->height - dst_loc[1], 189544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 0, 0); 190544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin else 191544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin renderer_copy_surface(ctx->renderer, 192544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src, 193544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[0], 194544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src->height - src_loc[1], 195544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src_loc[0] + src_loc[2], 196544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src->height - (src_loc[1] + src_loc[3]), 197544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst, 198544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[0], 199544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst->height - (dst_loc[1] + dst_loc[3]), 200544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst_loc[0] + dst_loc[2], 201544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst->height - dst_loc[1], 202544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 0, 0); 203544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 204544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 205544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 206544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 207287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwellstatic struct pipe_resource *image_texture(struct vg_image *img) 208544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 209287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell struct pipe_resource *tex = img->sampler_view->texture; 210544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return tex; 211544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 212544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 213544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 214544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinstatic void image_cleari(struct vg_image *img, VGint clear_colori, 215544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint x, VGint y, VGint width, VGint height) 216544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 217544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint *clearbuf; 218544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint i; 219544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat dwidth, dheight; 220544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 221544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin clearbuf = malloc(sizeof(VGint)*width*height); 222544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (i = 0; i < width*height; ++i) 223544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin clearbuf[i] = clear_colori; 224544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 225544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dwidth = MIN2(width, img->width); 226544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dheight = MIN2(height, img->height); 227544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 228544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image_sub_data(img, clearbuf, width * sizeof(VGint), 229544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VG_sRGBA_8888, 230544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x, y, dwidth, dheight); 231544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin free(clearbuf); 232544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 233544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 234544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinstruct vg_image * image_create(VGImageFormat format, 235544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 236544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 237544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 238e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger struct pipe_context *pipe = ctx->pipe; 239544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *image = CALLOC_STRUCT(vg_image); 240544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin enum pipe_format pformat = vg_format_to_pipe(format); 241287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell struct pipe_resource pt, *newtex; 242e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger struct pipe_sampler_view view_templ; 243e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger struct pipe_sampler_view *view; 244544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_screen *screen = ctx->pipe->screen; 245544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 246544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); 247544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 248544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->format = format; 249544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->width = width; 250544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->height = height; 251544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 252544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 253544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 254544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 255544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; 256544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; 257544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.normalized_coords = 1; 258544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 259544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin assert(screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, 260e968975cb57eb854769292f7c6ff773c64a386c3Marek Olšák 0, PIPE_BIND_SAMPLER_VIEW)); 261544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 262544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin memset(&pt, 0, sizeof(pt)); 263544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin pt.target = PIPE_TEXTURE_2D; 264544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin pt.format = pformat; 265544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin pt.last_level = 0; 266d509f84543d0979e9bb53c20c195f378dd61e728Roland Scheidegger pt.width0 = width; 267d509f84543d0979e9bb53c20c195f378dd61e728Roland Scheidegger pt.height0 = height; 268d509f84543d0979e9bb53c20c195f378dd61e728Roland Scheidegger pt.depth0 = 1; 2694c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pt.array_size = 1; 270287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell pt.bind = PIPE_BIND_SAMPLER_VIEW; 271544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 272287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell newtex = screen->resource_create(screen, &pt); 273544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 274544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin debug_assert(newtex); 275544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 276e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger u_sampler_view_default_template(&view_templ, newtex, newtex->format); 277d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu /* R, G, and B are treated as 1.0 for alpha-only formats in OpenVG */ 278d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu if (newtex->format == PIPE_FORMAT_A8_UNORM) { 279d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu view_templ.swizzle_r = PIPE_SWIZZLE_ONE; 280d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu view_templ.swizzle_g = PIPE_SWIZZLE_ONE; 281d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu view_templ.swizzle_b = PIPE_SWIZZLE_ONE; 282d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu } 283d873f1f5b63e7243c20751e92389e4189d39fd42Chia-I Wu 284e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger view = pipe->create_sampler_view(pipe, newtex, &view_templ); 285e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger /* want the texture to go away if the view is freed */ 286287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell pipe_resource_reference(&newtex, NULL); 287e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger 288e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger image->sampler_view = view; 289544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 290ceb6d34906c7c03c102c7e78dd02f5b0ebab4ca9Chia-I Wu vg_context_add_object(ctx, &image->base); 291544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 292544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image_cleari(image, 0, 0, 0, image->width, image->height); 293544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return image; 294544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 295544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 296544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_destroy(struct vg_image *img) 297544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 298544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 299ceb6d34906c7c03c102c7e78dd02f5b0ebab4ca9Chia-I Wu vg_context_remove_object(ctx, &img->base); 300544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 301544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 302544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (img->parent) { 303544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /* remove img from the parent child array */ 304544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin int idx; 305544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image **array = 306544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin (struct vg_image **)img->parent->children_array->data; 307544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 308544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (idx = 0; idx < img->parent->children_array->num_elements; ++idx) { 309544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *child = array[idx]; 310544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (child == img) { 311544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin break; 312544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 313544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 314544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin debug_assert(idx < img->parent->children_array->num_elements); 315544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin array_remove_element(img->parent->children_array, idx); 316544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 317544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 318544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (img->children_array && img->children_array->num_elements) { 319544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /* reparent the children */ 320544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint i; 321544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *parent = img->parent; 322544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image **children = 323544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin (struct vg_image **)img->children_array->data; 324544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (!parent) { 325544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint min_x = children[0]->x; 326544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin parent = children[0]; 327544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 328544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (i = 1; i < img->children_array->num_elements; ++i) { 329544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *child = children[i]; 330544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (child->x < min_x) { 331544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin parent = child; 332544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 333544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 334544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 335544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 336544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (i = 0; i < img->children_array->num_elements; ++i) { 337544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *child = children[i]; 338544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (child != parent) { 339544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin child->parent = parent; 340544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (!parent->children_array) { 341544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin parent->children_array = array_create( 342544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin sizeof(struct vg_image*)); 343544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 344544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin array_append_data(parent->children_array, 345544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin &child, 1); 346544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } else 347544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin child->parent = NULL; 348544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 349544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin array_destroy(img->children_array); 350544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 351544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 35299c67f27d35a4bbbbefada8117d5972c7583cf42Brian Paul vg_free_object(&img->base); 35399c67f27d35a4bbbbefada8117d5972c7583cf42Brian Paul 354e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger pipe_sampler_view_reference(&img->sampler_view, NULL); 355f914cd1796845164109c837a111c39ba64852ad4nobled FREE(img); 356544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 357544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 358544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_clear(struct vg_image *img, 359544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint x, VGint y, VGint width, VGint height) 360544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 361544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 362544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat *clear_colorf = ctx->state.vg.clear_color; 363544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGubyte r, g, b ,a; 364544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint clear_colori; 365544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /* FIXME: this is very nasty */ 366544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin r = float_to_ubyte(clear_colorf[0]); 367544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin g = float_to_ubyte(clear_colorf[1]); 368544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin b = float_to_ubyte(clear_colorf[2]); 369544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin a = float_to_ubyte(clear_colorf[3]); 370544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin clear_colori = r << 24 | g << 16 | b << 8 | a; 371544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image_cleari(img, clear_colori, x, y, width, height); 372544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 373544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 374544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_sub_data(struct vg_image *image, 375544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin const void * data, 376544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint dataStride, 377544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGImageFormat dataFormat, 378544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint x, VGint y, 379544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 380544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 381544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin const VGint yStep = 1; 382544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGubyte *src = (VGubyte *)data; 383544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; 384544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat *df = (VGfloat*)temp; 385544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint i; 386544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 387b43c182f19c6291c88420fa12714f952c2b461fbKeith Whitwell struct pipe_context *pipe = ctx->pipe; 388287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell struct pipe_resource *texture = image_texture(image); 389544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint xoffset = 0, yoffset = 0; 390544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 391544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (x < 0) { 392544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin xoffset -= x; 393544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin width += x; 394544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x = 0; 395544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 396544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (y < 0) { 397544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin yoffset -= y; 398544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin height += y; 399544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y = 0; 400544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 401544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 402544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (width <= 0 || height <= 0) { 403544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 404544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return; 405544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 406544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 407544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (x > image->width || y > image->width) { 408544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 409544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return; 410544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 411544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 412544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (x + width > image->width) { 413544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin width = image->width - x; 414544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 415544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 416544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (y + height > image->height) { 417544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin height = image->height - y; 418544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 419544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 420544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin { /* upload color_data */ 421287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell struct pipe_transfer *transfer = pipe_get_transfer( 4224c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe, texture, 0, 0, 423d509f84543d0979e9bb53c20c195f378dd61e728Roland Scheidegger PIPE_TRANSFER_WRITE, 0, 0, texture->width0, texture->height0); 424544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src += (dataStride * yoffset); 425544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (i = 0; i < height; i++) { 426544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin _vega_unpack_float_span_rgba(ctx, width, xoffset, src, dataFormat, temp); 427d35ecca5ee231c072687578642e0c22c6c0590b1Keith Whitwell pipe_put_tile_rgba(pipe, transfer, x+image->x, y+image->y, width, 1, df); 428544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y += yStep; 429544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin src += dataStride; 430544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 431287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell pipe->transfer_destroy(pipe, transfer); 432544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 433544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 434544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 435544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_get_sub_data(struct vg_image * image, 436544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin void * data, 437544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint dataStride, 438544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGImageFormat dataFormat, 439544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint sx, VGint sy, 440544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 441544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 442544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 443544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_context *pipe = ctx->pipe; 444544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat temp[VEGA_MAX_IMAGE_WIDTH][4]; 445544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat *df = (VGfloat*)temp; 446544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint y = 0, yStep = 1; 447544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint i; 448544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGubyte *dst = (VGubyte *)data; 449544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 450544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin { 451544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_transfer *transfer = 452287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell pipe_get_transfer(pipe, 4534c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger image->sampler_view->texture, 0, 0, 4544c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger PIPE_TRANSFER_READ, 4554c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger 0, 0, 4564c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger image->x + image->width, 4574c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger image->y + image->height); 458544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /* Do a row at a time to flip image data vertically */ 459544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin for (i = 0; i < height; i++) { 460544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#if 0 461544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin debug_printf("%d-%d == %d\n", sy, height, y); 462544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin#endif 463d35ecca5ee231c072687578642e0c22c6c0590b1Keith Whitwell pipe_get_tile_rgba(pipe, transfer, sx+image->x, y, width, 1, df); 464544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y += yStep; 465544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin _vega_pack_rgba_span_float(ctx, width, temp, dataFormat, dst); 466544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst += dataStride; 467544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 468544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 469287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell pipe->transfer_destroy(pipe, transfer); 470544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 471544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 472544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 473544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinstruct vg_image * image_child_image(struct vg_image *parent, 474544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint x, VGint y, 475544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 476544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 477544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 478544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *image = CALLOC_STRUCT(vg_image); 479544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 480544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_init_object(&image->base, ctx, VG_OBJECT_IMAGE); 481544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 482544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->x = parent->x + x; 483544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->y = parent->y + y; 484544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->width = width; 485544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->height = height; 486544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->parent = parent; 487e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger image->sampler_view = NULL; 488e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger pipe_sampler_view_reference(&image->sampler_view, 489e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger parent->sampler_view); 490544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 491544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 492544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 493544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; 494544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.min_img_filter = PIPE_TEX_MIPFILTER_NEAREST; 495544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.mag_img_filter = PIPE_TEX_MIPFILTER_NEAREST; 496544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin image->sampler.normalized_coords = 1; 497544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 498544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (!parent->children_array) 499544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin parent->children_array = array_create( 500544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin sizeof(struct vg_image*)); 501544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 502544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin array_append_data(parent->children_array, 503544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin &image, 1); 504544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 505ceb6d34906c7c03c102c7e78dd02f5b0ebab4ca9Chia-I Wu vg_context_add_object(ctx, &image->base); 506544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 507544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return image; 508544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 509544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 510544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_copy(struct vg_image *dst, VGint dx, VGint dy, 511544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *src, VGint sx, VGint sy, 512544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height, 513544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGboolean dither) 514544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 515544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 516544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 517544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (width <= 0 || height <= 0) { 518544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_set_error(ctx, VG_ILLEGAL_ARGUMENT_ERROR); 519544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return; 520544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 521e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger vg_copy_texture(ctx, dst->sampler_view->texture, dst->x + dx, dst->y + dy, 522e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger src->sampler_view, src->x + sx, src->y + sy, width, height); 523544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 524544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 52534f466d4e6a720138c0846ab6233c32dc039fe58Chia-I Wuvoid image_draw(struct vg_image *img, struct matrix *matrix) 526544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 527544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 528b06de80843e7d096bed4ae03ddc5e2842f1876afChia-I Wu struct matrix paint_matrix; 529544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat x1, y1; 530544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat x2, y2; 531544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat x3, y3; 532544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat x4, y4; 533544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 53406e7a5502817d9df7f023083b135c8cd327c3e6cChia-I Wu if (!vg_get_paint_matrix(ctx, 53506e7a5502817d9df7f023083b135c8cd327c3e6cChia-I Wu &ctx->state.vg.fill_paint_to_user_matrix, 53606e7a5502817d9df7f023083b135c8cd327c3e6cChia-I Wu matrix, 53706e7a5502817d9df7f023083b135c8cd327c3e6cChia-I Wu &paint_matrix)) 538b06de80843e7d096bed4ae03ddc5e2842f1876afChia-I Wu return; 539b06de80843e7d096bed4ae03ddc5e2842f1876afChia-I Wu 540544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x1 = 0; 541544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y1 = 0; 542544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x2 = img->width; 543544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y2 = 0; 544544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x3 = img->width; 545544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y3 = img->height; 546544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x4 = 0; 547544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin y4 = img->height; 548544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 549a84a1e344f544ec4da61809d4f09853a94d93e07Chia-I Wu shader_set_surface_matrix(ctx->shader, matrix); 550544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shader_set_drawing_image(ctx->shader, VG_TRUE); 551544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shader_set_paint(ctx->shader, ctx->state.vg.fill_paint); 552b06de80843e7d096bed4ae03ddc5e2842f1876afChia-I Wu shader_set_paint_matrix(ctx->shader, &paint_matrix); 553544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shader_set_image(ctx->shader, img); 554544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin shader_bind(ctx->shader); 555544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 556544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin renderer_texture_quad(ctx->renderer, image_texture(img), 557544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin img->x, img->y, img->x + img->width, img->y + img->height, 558544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin x1, y1, x2, y2, x3, y3, x4, y4); 559544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 560544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 561544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_set_pixels(VGint dx, VGint dy, 562544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *src, VGint sx, VGint sy, 563544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 564544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 565544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 566544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_context *pipe = ctx->pipe; 5674c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger struct pipe_surface *surf, surf_tmpl; 568544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct st_renderbuffer *strb = ctx->draw_buffer->strb; 569544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 5704c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger memset(&surf_tmpl, 0, sizeof(surf_tmpl)); 5714c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger u_surface_default_template(&surf_tmpl, image_texture(src), 5724c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger 0 /* no bind flag - not a surface*/); 5734c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger surf = pipe->create_surface(pipe, image_texture(src), &surf_tmpl); 574544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 575544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_copy_surface(ctx, strb->surface, dx, dy, 576544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin surf, sx+src->x, sy+src->y, width, height); 577544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 5784c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger pipe->surface_destroy(pipe, surf); 579544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 580544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 581544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusinvoid image_get_pixels(struct vg_image *dst, VGint dx, VGint dy, 582544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint sx, VGint sy, 583544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGint width, VGint height) 584544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 585544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_context *ctx = vg_current_context(); 586544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct pipe_context *pipe = ctx->pipe; 5874c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger struct pipe_surface *surf, surf_tmpl; 588544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct st_renderbuffer *strb = ctx->draw_buffer->strb; 589544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 590544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /* flip the y coordinates */ 591544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin /*dy = dst->height - dy - height;*/ 592544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 5934c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger memset(&surf_tmpl, 0, sizeof(surf_tmpl)); 5944c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger u_surface_default_template(&surf_tmpl, image_texture(dst), 5954c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger PIPE_BIND_RENDER_TARGET); 5964c7001462607e6e99e474d6271dd481d3f8f201cRoland Scheidegger surf = pipe->create_surface(pipe, image_texture(dst), &surf_tmpl); 597287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell 598544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin vg_copy_surface(ctx, surf, dst->x + dx, dst->y + dy, 599544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin strb->surface, sx, sy, width, height); 600544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 601544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin pipe_surface_reference(&surf, NULL); 602544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 603544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 604544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 605544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack RusinVGboolean vg_image_overlaps(struct vg_image *dst, 606544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin struct vg_image *src) 607544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 608544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (dst == src || dst->parent == src || 609544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin dst == src->parent) 610544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return VG_TRUE; 611544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin if (dst->parent && dst->parent == src->parent) { 612544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat left1 = dst->x; 613544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat left2 = src->x; 614544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat right1 = dst->x + dst->width; 615544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat right2 = src->x + src->width; 616544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat bottom1 = dst->y; 617544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat bottom2 = src->y; 618544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat top1 = dst->y + dst->height; 619544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin VGfloat top2 = src->y + src->height; 620544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 621544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return !(left2 > right1 || right2 < left1 || 622544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin top2 > bottom1 || bottom2 < top1); 623544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 624544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return VG_FALSE; 625544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 626544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 627544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack RusinVGint image_bind_samplers(struct vg_image *img, struct pipe_sampler_state **samplers, 628e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger struct pipe_sampler_view **sampler_views) 629544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 630544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin img->sampler.min_img_filter = image_sampler_filter(img->base.ctx); 631544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin img->sampler.mag_img_filter = image_sampler_filter(img->base.ctx); 632544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin samplers[3] = &img->sampler; 633e5f0384ad06359aa1b9dc1b4bc6f475f7a119af2Roland Scheidegger sampler_views[3] = img->sampler_view; 634544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return 1; 635544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 636544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin 637544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack RusinVGint image_sampler_filter(struct vg_context *ctx) 638544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin{ 639544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin switch(ctx->state.vg.image_quality) { 640544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_IMAGE_QUALITY_NONANTIALIASED: 641544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_TEX_FILTER_NEAREST; 642544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin break; 643544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_IMAGE_QUALITY_FASTER: 644544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_TEX_FILTER_NEAREST; 645544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin break; 646544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin case VG_IMAGE_QUALITY_BETTER: 647f02347374819a9b145a3e26c625709aea0c6f61bLuca Barbieri /* possibly use anisotropic filtering */ 648544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_TEX_FILTER_LINEAR; 649544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin break; 650544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin default: 651544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin debug_printf("Unknown image quality"); 652544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin } 653544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin return PIPE_TEX_FILTER_NEAREST; 654544dd4b11f7be76bb00fe29a60eaf2772dcc69caZack Rusin} 655