r600_blit.c revision 3e58007892cb2e89cb979ab172b7160adc84a44d
1/* 2 * Copyright 2009 Marek Olšák <maraeo@gmail.com> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * on the rights to use, copy, modify, merge, publish, distribute, sub 8 * license, and/or sell copies of the Software, and to permit persons to whom 9 * the Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 21 * USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Jerome Glisse 25 * Marek Olšák 26 */ 27#include <pipe/p_screen.h> 28#include <util/u_blitter.h> 29#include <util/u_inlines.h> 30#include <util/u_memory.h> 31#include "util/u_surface.h" 32#include "r600_screen.h" 33#include "r600_context.h" 34 35static void r600_blitter_save_states(struct r600_context *rctx) 36{ 37 util_blitter_save_blend(rctx->blitter, rctx->blend); 38 util_blitter_save_depth_stencil_alpha(rctx->blitter, rctx->dsa); 39 if (rctx->stencil_ref) { 40 util_blitter_save_stencil_ref(rctx->blitter, 41 &rctx->stencil_ref->state.stencil_ref); 42 } 43 util_blitter_save_rasterizer(rctx->blitter, rctx->rasterizer); 44 util_blitter_save_fragment_shader(rctx->blitter, rctx->ps_shader); 45 util_blitter_save_vertex_shader(rctx->blitter, rctx->vs_shader); 46 util_blitter_save_vertex_elements(rctx->blitter, rctx->vertex_elements); 47 if (rctx->viewport) { 48 util_blitter_save_viewport(rctx->blitter, &rctx->viewport->state.viewport); 49 } 50 if (rctx->clip) 51 util_blitter_save_clip(rctx->blitter, &rctx->clip->state.clip); 52 util_blitter_save_vertex_buffers(rctx->blitter, rctx->nvertex_buffer, 53 rctx->vertex_buffer); 54 55 /* remove ptr so they don't get deleted */ 56 rctx->blend = NULL; 57 rctx->clip = NULL; 58 rctx->vs_shader = NULL; 59 rctx->ps_shader = NULL; 60 rctx->rasterizer = NULL; 61 rctx->dsa = NULL; 62 rctx->vertex_elements = NULL; 63} 64 65static void r600_clear(struct pipe_context *ctx, unsigned buffers, 66 const float *rgba, double depth, unsigned stencil) 67{ 68 struct r600_context *rctx = r600_context(ctx); 69 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer; 70 71 r600_blitter_save_states(rctx); 72 util_blitter_clear(rctx->blitter, fb->width, fb->height, 73 fb->nr_cbufs, buffers, rgba, depth, 74 stencil); 75} 76 77static void r600_clear_render_target(struct pipe_context *pipe, 78 struct pipe_surface *dst, 79 const float *rgba, 80 unsigned dstx, unsigned dsty, 81 unsigned width, unsigned height) 82{ 83 struct r600_context *rctx = r600_context(pipe); 84 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer; 85 86 r600_blitter_save_states(rctx); 87 util_blitter_save_framebuffer(rctx->blitter, fb); 88 89 util_blitter_clear_render_target(rctx->blitter, dst, rgba, 90 dstx, dsty, width, height); 91} 92 93static void r600_clear_depth_stencil(struct pipe_context *pipe, 94 struct pipe_surface *dst, 95 unsigned clear_flags, 96 double depth, 97 unsigned stencil, 98 unsigned dstx, unsigned dsty, 99 unsigned width, unsigned height) 100{ 101 struct r600_context *rctx = r600_context(pipe); 102 struct pipe_framebuffer_state *fb = &rctx->framebuffer->state.framebuffer; 103 104 r600_blitter_save_states(rctx); 105 util_blitter_save_framebuffer(rctx->blitter, fb); 106 107 util_blitter_clear_depth_stencil(rctx->blitter, dst, clear_flags, depth, stencil, 108 dstx, dsty, width, height); 109} 110 111static void r600_resource_copy_region(struct pipe_context *pipe, 112 struct pipe_resource *dst, 113 struct pipe_subresource subdst, 114 unsigned dstx, unsigned dsty, unsigned dstz, 115 struct pipe_resource *src, 116 struct pipe_subresource subsrc, 117 unsigned srcx, unsigned srcy, unsigned srcz, 118 unsigned width, unsigned height) 119{ 120 util_resource_copy_region(pipe, dst, subdst, dstx, dsty, dstz, 121 src, subsrc, srcx, srcy, srcz, width, height); 122} 123 124void r600_init_blit_functions(struct r600_context *rctx) 125{ 126 rctx->context.clear = r600_clear; 127 rctx->context.clear_render_target = r600_clear_render_target; 128 rctx->context.clear_depth_stencil = r600_clear_depth_stencil; 129 rctx->context.resource_copy_region = r600_resource_copy_region; 130} 131