1*61046927SAndroid Build Coastguard Worker /**************************************************************************
2*61046927SAndroid Build Coastguard Worker *
3*61046927SAndroid Build Coastguard Worker * Copyright 2009, VMware, Inc.
4*61046927SAndroid Build Coastguard Worker * All Rights Reserved.
5*61046927SAndroid Build Coastguard Worker * Copyright 2010 George Sapountzis <[email protected]>
6*61046927SAndroid Build Coastguard Worker *
7*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
8*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the
9*61046927SAndroid Build Coastguard Worker * "Software"), to deal in the Software without restriction, including
10*61046927SAndroid Build Coastguard Worker * without limitation the rights to use, copy, modify, merge, publish,
11*61046927SAndroid Build Coastguard Worker * distribute, sub license, and/or sell copies of the Software, and to
12*61046927SAndroid Build Coastguard Worker * permit persons to whom the Software is furnished to do so, subject to
13*61046927SAndroid Build Coastguard Worker * the following conditions:
14*61046927SAndroid Build Coastguard Worker *
15*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the
16*61046927SAndroid Build Coastguard Worker * next paragraph) shall be included in all copies or substantial portions
17*61046927SAndroid Build Coastguard Worker * of the Software.
18*61046927SAndroid Build Coastguard Worker *
19*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20*61046927SAndroid Build Coastguard Worker * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21*61046927SAndroid Build Coastguard Worker * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22*61046927SAndroid Build Coastguard Worker * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23*61046927SAndroid Build Coastguard Worker * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24*61046927SAndroid Build Coastguard Worker * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25*61046927SAndroid Build Coastguard Worker * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26*61046927SAndroid Build Coastguard Worker *
27*61046927SAndroid Build Coastguard Worker **************************************************************************/
28*61046927SAndroid Build Coastguard Worker
29*61046927SAndroid Build Coastguard Worker #include "mesa_interface.h"
30*61046927SAndroid Build Coastguard Worker #include "git_sha1.h"
31*61046927SAndroid Build Coastguard Worker #include "util/format/u_format.h"
32*61046927SAndroid Build Coastguard Worker #include "util/u_memory.h"
33*61046927SAndroid Build Coastguard Worker #include "util/u_inlines.h"
34*61046927SAndroid Build Coastguard Worker #include "util/box.h"
35*61046927SAndroid Build Coastguard Worker #include "pipe/p_context.h"
36*61046927SAndroid Build Coastguard Worker #include "pipe-loader/pipe_loader.h"
37*61046927SAndroid Build Coastguard Worker #include "frontend/drisw_api.h"
38*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_context.h"
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard Worker #include "dri_screen.h"
41*61046927SAndroid Build Coastguard Worker #include "dri_context.h"
42*61046927SAndroid Build Coastguard Worker #include "dri_drawable.h"
43*61046927SAndroid Build Coastguard Worker #include "dri_helpers.h"
44*61046927SAndroid Build Coastguard Worker #include "dri_query_renderer.h"
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard Worker #include "util/libsync.h"
47*61046927SAndroid Build Coastguard Worker
48*61046927SAndroid Build Coastguard Worker #ifdef HAVE_LIBDRM
49*61046927SAndroid Build Coastguard Worker #include <xf86drm.h>
50*61046927SAndroid Build Coastguard Worker #endif
51*61046927SAndroid Build Coastguard Worker
52*61046927SAndroid Build Coastguard Worker DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", false);
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker static inline void
get_drawable_info(struct dri_drawable * drawable,int * x,int * y,int * w,int * h)55*61046927SAndroid Build Coastguard Worker get_drawable_info(struct dri_drawable *drawable, int *x, int *y, int *w, int *h)
56*61046927SAndroid Build Coastguard Worker {
57*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
58*61046927SAndroid Build Coastguard Worker
59*61046927SAndroid Build Coastguard Worker loader->getDrawableInfo(opaque_dri_drawable(drawable),
60*61046927SAndroid Build Coastguard Worker x, y, w, h,
61*61046927SAndroid Build Coastguard Worker drawable->loaderPrivate);
62*61046927SAndroid Build Coastguard Worker }
63*61046927SAndroid Build Coastguard Worker
64*61046927SAndroid Build Coastguard Worker static inline void
put_image(struct dri_drawable * drawable,void * data,unsigned width,unsigned height)65*61046927SAndroid Build Coastguard Worker put_image(struct dri_drawable *drawable, void *data, unsigned width, unsigned height)
66*61046927SAndroid Build Coastguard Worker {
67*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
68*61046927SAndroid Build Coastguard Worker
69*61046927SAndroid Build Coastguard Worker loader->putImage(opaque_dri_drawable(drawable), __DRI_SWRAST_IMAGE_OP_SWAP,
70*61046927SAndroid Build Coastguard Worker 0, 0, width, height,
71*61046927SAndroid Build Coastguard Worker data, drawable->loaderPrivate);
72*61046927SAndroid Build Coastguard Worker }
73*61046927SAndroid Build Coastguard Worker
74*61046927SAndroid Build Coastguard Worker static inline void
put_image2(struct dri_drawable * drawable,void * data,int x,int y,unsigned width,unsigned height,unsigned stride)75*61046927SAndroid Build Coastguard Worker put_image2(struct dri_drawable *drawable, void *data, int x, int y,
76*61046927SAndroid Build Coastguard Worker unsigned width, unsigned height, unsigned stride)
77*61046927SAndroid Build Coastguard Worker {
78*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
79*61046927SAndroid Build Coastguard Worker
80*61046927SAndroid Build Coastguard Worker loader->putImage2(opaque_dri_drawable(drawable), __DRI_SWRAST_IMAGE_OP_SWAP,
81*61046927SAndroid Build Coastguard Worker x, y, width, height, stride,
82*61046927SAndroid Build Coastguard Worker data, drawable->loaderPrivate);
83*61046927SAndroid Build Coastguard Worker }
84*61046927SAndroid Build Coastguard Worker
85*61046927SAndroid Build Coastguard Worker static inline void
put_image_shm(struct dri_drawable * drawable,int shmid,char * shmaddr,unsigned offset,unsigned offset_x,int x,int y,unsigned width,unsigned height,unsigned stride)86*61046927SAndroid Build Coastguard Worker put_image_shm(struct dri_drawable *drawable, int shmid, char *shmaddr,
87*61046927SAndroid Build Coastguard Worker unsigned offset, unsigned offset_x, int x, int y,
88*61046927SAndroid Build Coastguard Worker unsigned width, unsigned height, unsigned stride)
89*61046927SAndroid Build Coastguard Worker {
90*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
91*61046927SAndroid Build Coastguard Worker
92*61046927SAndroid Build Coastguard Worker /* if we have the newer interface, don't have to add the offset_x here. */
93*61046927SAndroid Build Coastguard Worker if (loader->base.version > 4 && loader->putImageShm2)
94*61046927SAndroid Build Coastguard Worker loader->putImageShm2(opaque_dri_drawable(drawable), __DRI_SWRAST_IMAGE_OP_SWAP,
95*61046927SAndroid Build Coastguard Worker x, y, width, height, stride,
96*61046927SAndroid Build Coastguard Worker shmid, shmaddr, offset, drawable->loaderPrivate);
97*61046927SAndroid Build Coastguard Worker else
98*61046927SAndroid Build Coastguard Worker loader->putImageShm(opaque_dri_drawable(drawable), __DRI_SWRAST_IMAGE_OP_SWAP,
99*61046927SAndroid Build Coastguard Worker x, y, width, height, stride,
100*61046927SAndroid Build Coastguard Worker shmid, shmaddr, offset + offset_x, drawable->loaderPrivate);
101*61046927SAndroid Build Coastguard Worker }
102*61046927SAndroid Build Coastguard Worker
103*61046927SAndroid Build Coastguard Worker static inline void
get_image(struct dri_drawable * drawable,int x,int y,int width,int height,void * data)104*61046927SAndroid Build Coastguard Worker get_image(struct dri_drawable *drawable, int x, int y, int width, int height, void *data)
105*61046927SAndroid Build Coastguard Worker {
106*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
107*61046927SAndroid Build Coastguard Worker
108*61046927SAndroid Build Coastguard Worker loader->getImage(opaque_dri_drawable(drawable),
109*61046927SAndroid Build Coastguard Worker x, y, width, height,
110*61046927SAndroid Build Coastguard Worker data, drawable->loaderPrivate);
111*61046927SAndroid Build Coastguard Worker }
112*61046927SAndroid Build Coastguard Worker
113*61046927SAndroid Build Coastguard Worker static inline void
get_image2(struct dri_drawable * drawable,int x,int y,int width,int height,int stride,void * data)114*61046927SAndroid Build Coastguard Worker get_image2(struct dri_drawable *drawable, int x, int y, int width, int height, int stride, void *data)
115*61046927SAndroid Build Coastguard Worker {
116*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
117*61046927SAndroid Build Coastguard Worker
118*61046927SAndroid Build Coastguard Worker /* getImage2 support is only in version 3 or newer */
119*61046927SAndroid Build Coastguard Worker if (loader->base.version < 3)
120*61046927SAndroid Build Coastguard Worker return;
121*61046927SAndroid Build Coastguard Worker
122*61046927SAndroid Build Coastguard Worker loader->getImage2(opaque_dri_drawable(drawable),
123*61046927SAndroid Build Coastguard Worker x, y, width, height, stride,
124*61046927SAndroid Build Coastguard Worker data, drawable->loaderPrivate);
125*61046927SAndroid Build Coastguard Worker }
126*61046927SAndroid Build Coastguard Worker
127*61046927SAndroid Build Coastguard Worker static inline bool
get_image_shm(struct dri_drawable * drawable,int x,int y,int width,int height,struct pipe_resource * res)128*61046927SAndroid Build Coastguard Worker get_image_shm(struct dri_drawable *drawable, int x, int y, int width, int height,
129*61046927SAndroid Build Coastguard Worker struct pipe_resource *res)
130*61046927SAndroid Build Coastguard Worker {
131*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
132*61046927SAndroid Build Coastguard Worker struct winsys_handle whandle;
133*61046927SAndroid Build Coastguard Worker
134*61046927SAndroid Build Coastguard Worker whandle.type = WINSYS_HANDLE_TYPE_SHMID;
135*61046927SAndroid Build Coastguard Worker
136*61046927SAndroid Build Coastguard Worker if (loader->base.version < 4 || !loader->getImageShm)
137*61046927SAndroid Build Coastguard Worker return false;
138*61046927SAndroid Build Coastguard Worker
139*61046927SAndroid Build Coastguard Worker if (!res->screen->resource_get_handle(res->screen, NULL, res, &whandle, PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE))
140*61046927SAndroid Build Coastguard Worker return false;
141*61046927SAndroid Build Coastguard Worker
142*61046927SAndroid Build Coastguard Worker if (loader->base.version > 5 && loader->getImageShm2)
143*61046927SAndroid Build Coastguard Worker return loader->getImageShm2(opaque_dri_drawable(drawable), x, y, width, height, whandle.handle, drawable->loaderPrivate);
144*61046927SAndroid Build Coastguard Worker
145*61046927SAndroid Build Coastguard Worker loader->getImageShm(opaque_dri_drawable(drawable), x, y, width, height, whandle.handle, drawable->loaderPrivate);
146*61046927SAndroid Build Coastguard Worker return true;
147*61046927SAndroid Build Coastguard Worker }
148*61046927SAndroid Build Coastguard Worker
149*61046927SAndroid Build Coastguard Worker static void
drisw_update_drawable_info(struct dri_drawable * drawable)150*61046927SAndroid Build Coastguard Worker drisw_update_drawable_info(struct dri_drawable *drawable)
151*61046927SAndroid Build Coastguard Worker {
152*61046927SAndroid Build Coastguard Worker int x, y;
153*61046927SAndroid Build Coastguard Worker
154*61046927SAndroid Build Coastguard Worker get_drawable_info(drawable, &x, &y, &drawable->w, &drawable->h);
155*61046927SAndroid Build Coastguard Worker }
156*61046927SAndroid Build Coastguard Worker
157*61046927SAndroid Build Coastguard Worker static void
drisw_get_image(struct dri_drawable * drawable,int x,int y,unsigned width,unsigned height,unsigned stride,void * data)158*61046927SAndroid Build Coastguard Worker drisw_get_image(struct dri_drawable *drawable,
159*61046927SAndroid Build Coastguard Worker int x, int y, unsigned width, unsigned height, unsigned stride,
160*61046927SAndroid Build Coastguard Worker void *data)
161*61046927SAndroid Build Coastguard Worker {
162*61046927SAndroid Build Coastguard Worker int draw_x, draw_y, draw_w, draw_h;
163*61046927SAndroid Build Coastguard Worker
164*61046927SAndroid Build Coastguard Worker get_drawable_info(drawable, &draw_x, &draw_y, &draw_w, &draw_h);
165*61046927SAndroid Build Coastguard Worker get_image2(drawable, x, y, draw_w, draw_h, stride, data);
166*61046927SAndroid Build Coastguard Worker }
167*61046927SAndroid Build Coastguard Worker
168*61046927SAndroid Build Coastguard Worker static void
drisw_put_image(struct dri_drawable * drawable,void * data,unsigned width,unsigned height)169*61046927SAndroid Build Coastguard Worker drisw_put_image(struct dri_drawable *drawable,
170*61046927SAndroid Build Coastguard Worker void *data, unsigned width, unsigned height)
171*61046927SAndroid Build Coastguard Worker {
172*61046927SAndroid Build Coastguard Worker put_image(drawable, data, width, height);
173*61046927SAndroid Build Coastguard Worker }
174*61046927SAndroid Build Coastguard Worker
175*61046927SAndroid Build Coastguard Worker static void
drisw_put_image2(struct dri_drawable * drawable,void * data,int x,int y,unsigned width,unsigned height,unsigned stride)176*61046927SAndroid Build Coastguard Worker drisw_put_image2(struct dri_drawable *drawable,
177*61046927SAndroid Build Coastguard Worker void *data, int x, int y, unsigned width, unsigned height,
178*61046927SAndroid Build Coastguard Worker unsigned stride)
179*61046927SAndroid Build Coastguard Worker {
180*61046927SAndroid Build Coastguard Worker put_image2(drawable, data, x, y, width, height, stride);
181*61046927SAndroid Build Coastguard Worker }
182*61046927SAndroid Build Coastguard Worker
183*61046927SAndroid Build Coastguard Worker static inline void
drisw_put_image_shm(struct dri_drawable * drawable,int shmid,char * shmaddr,unsigned offset,unsigned offset_x,int x,int y,unsigned width,unsigned height,unsigned stride)184*61046927SAndroid Build Coastguard Worker drisw_put_image_shm(struct dri_drawable *drawable,
185*61046927SAndroid Build Coastguard Worker int shmid, char *shmaddr, unsigned offset,
186*61046927SAndroid Build Coastguard Worker unsigned offset_x,
187*61046927SAndroid Build Coastguard Worker int x, int y, unsigned width, unsigned height,
188*61046927SAndroid Build Coastguard Worker unsigned stride)
189*61046927SAndroid Build Coastguard Worker {
190*61046927SAndroid Build Coastguard Worker put_image_shm(drawable, shmid, shmaddr, offset, offset_x, x, y, width, height, stride);
191*61046927SAndroid Build Coastguard Worker }
192*61046927SAndroid Build Coastguard Worker
193*61046927SAndroid Build Coastguard Worker static inline void
drisw_present_texture(struct pipe_context * pipe,struct dri_drawable * drawable,struct pipe_resource * ptex,unsigned nrects,struct pipe_box * sub_box)194*61046927SAndroid Build Coastguard Worker drisw_present_texture(struct pipe_context *pipe, struct dri_drawable *drawable,
195*61046927SAndroid Build Coastguard Worker struct pipe_resource *ptex, unsigned nrects, struct pipe_box *sub_box)
196*61046927SAndroid Build Coastguard Worker {
197*61046927SAndroid Build Coastguard Worker struct dri_screen *screen = drawable->screen;
198*61046927SAndroid Build Coastguard Worker
199*61046927SAndroid Build Coastguard Worker if (screen->swrast_no_present)
200*61046927SAndroid Build Coastguard Worker return;
201*61046927SAndroid Build Coastguard Worker
202*61046927SAndroid Build Coastguard Worker screen->base.screen->flush_frontbuffer(screen->base.screen, pipe, ptex, 0, 0, drawable, nrects, sub_box);
203*61046927SAndroid Build Coastguard Worker }
204*61046927SAndroid Build Coastguard Worker
205*61046927SAndroid Build Coastguard Worker static inline void
drisw_invalidate_drawable(struct dri_drawable * drawable)206*61046927SAndroid Build Coastguard Worker drisw_invalidate_drawable(struct dri_drawable *drawable)
207*61046927SAndroid Build Coastguard Worker {
208*61046927SAndroid Build Coastguard Worker drawable->texture_stamp = drawable->lastStamp - 1;
209*61046927SAndroid Build Coastguard Worker
210*61046927SAndroid Build Coastguard Worker p_atomic_inc(&drawable->base.stamp);
211*61046927SAndroid Build Coastguard Worker }
212*61046927SAndroid Build Coastguard Worker
213*61046927SAndroid Build Coastguard Worker static inline void
drisw_copy_to_front(struct pipe_context * pipe,struct dri_drawable * drawable,struct pipe_resource * ptex,int nboxes,struct pipe_box * boxes)214*61046927SAndroid Build Coastguard Worker drisw_copy_to_front(struct pipe_context *pipe,
215*61046927SAndroid Build Coastguard Worker struct dri_drawable *drawable,
216*61046927SAndroid Build Coastguard Worker struct pipe_resource *ptex,
217*61046927SAndroid Build Coastguard Worker int nboxes, struct pipe_box *boxes)
218*61046927SAndroid Build Coastguard Worker {
219*61046927SAndroid Build Coastguard Worker drisw_present_texture(pipe, drawable, ptex, nboxes, boxes);
220*61046927SAndroid Build Coastguard Worker
221*61046927SAndroid Build Coastguard Worker drisw_invalidate_drawable(drawable);
222*61046927SAndroid Build Coastguard Worker }
223*61046927SAndroid Build Coastguard Worker
224*61046927SAndroid Build Coastguard Worker /*
225*61046927SAndroid Build Coastguard Worker * Backend functions for pipe_frontend_drawable and swap_buffers.
226*61046927SAndroid Build Coastguard Worker */
227*61046927SAndroid Build Coastguard Worker
228*61046927SAndroid Build Coastguard Worker static void
drisw_swap_buffers_with_damage(struct dri_drawable * drawable,int nrects,const int * rects)229*61046927SAndroid Build Coastguard Worker drisw_swap_buffers_with_damage(struct dri_drawable *drawable, int nrects, const int *rects)
230*61046927SAndroid Build Coastguard Worker {
231*61046927SAndroid Build Coastguard Worker struct dri_context *ctx = dri_get_current();
232*61046927SAndroid Build Coastguard Worker struct dri_screen *screen = drawable->screen;
233*61046927SAndroid Build Coastguard Worker struct pipe_resource *ptex;
234*61046927SAndroid Build Coastguard Worker
235*61046927SAndroid Build Coastguard Worker if (!ctx)
236*61046927SAndroid Build Coastguard Worker return;
237*61046927SAndroid Build Coastguard Worker
238*61046927SAndroid Build Coastguard Worker /* Wait for glthread to finish because we can't use pipe_context from
239*61046927SAndroid Build Coastguard Worker * multiple threads.
240*61046927SAndroid Build Coastguard Worker */
241*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish(ctx->st->ctx);
242*61046927SAndroid Build Coastguard Worker
243*61046927SAndroid Build Coastguard Worker ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
244*61046927SAndroid Build Coastguard Worker
245*61046927SAndroid Build Coastguard Worker if (ptex) {
246*61046927SAndroid Build Coastguard Worker struct pipe_fence_handle *fence = NULL;
247*61046927SAndroid Build Coastguard Worker
248*61046927SAndroid Build Coastguard Worker struct pipe_box stack_boxes[64];
249*61046927SAndroid Build Coastguard Worker if (nrects > ARRAY_SIZE(stack_boxes))
250*61046927SAndroid Build Coastguard Worker nrects = 0;
251*61046927SAndroid Build Coastguard Worker if (nrects) {
252*61046927SAndroid Build Coastguard Worker for (unsigned int i = 0; i < nrects; i++) {
253*61046927SAndroid Build Coastguard Worker const int *rect = &rects[i * 4];
254*61046927SAndroid Build Coastguard Worker
255*61046927SAndroid Build Coastguard Worker int w = MIN2(rect[2], ptex->width0);
256*61046927SAndroid Build Coastguard Worker int h = MIN2(rect[3], ptex->height0);
257*61046927SAndroid Build Coastguard Worker int x = CLAMP(rect[0], 0, ptex->width0);
258*61046927SAndroid Build Coastguard Worker int y = CLAMP(ptex->height0 - rect[1] - h, 0, ptex->height0);
259*61046927SAndroid Build Coastguard Worker
260*61046927SAndroid Build Coastguard Worker if (h > ptex->height0 - y)
261*61046927SAndroid Build Coastguard Worker h = ptex->height0 - y;
262*61046927SAndroid Build Coastguard Worker
263*61046927SAndroid Build Coastguard Worker u_box_2d(x, y, w, h, &stack_boxes[i]);
264*61046927SAndroid Build Coastguard Worker }
265*61046927SAndroid Build Coastguard Worker }
266*61046927SAndroid Build Coastguard Worker
267*61046927SAndroid Build Coastguard Worker if (ctx->pp)
268*61046927SAndroid Build Coastguard Worker pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
269*61046927SAndroid Build Coastguard Worker
270*61046927SAndroid Build Coastguard Worker if (ctx->hud)
271*61046927SAndroid Build Coastguard Worker hud_run(ctx->hud, ctx->st->cso_context, ptex);
272*61046927SAndroid Build Coastguard Worker
273*61046927SAndroid Build Coastguard Worker st_context_flush(ctx->st, ST_FLUSH_FRONT, &fence, NULL, NULL);
274*61046927SAndroid Build Coastguard Worker
275*61046927SAndroid Build Coastguard Worker if (drawable->stvis.samples > 1) {
276*61046927SAndroid Build Coastguard Worker /* Resolve the back buffer. */
277*61046927SAndroid Build Coastguard Worker dri_pipe_blit(ctx->st->pipe,
278*61046927SAndroid Build Coastguard Worker drawable->textures[ST_ATTACHMENT_BACK_LEFT],
279*61046927SAndroid Build Coastguard Worker drawable->msaa_textures[ST_ATTACHMENT_BACK_LEFT]);
280*61046927SAndroid Build Coastguard Worker }
281*61046927SAndroid Build Coastguard Worker
282*61046927SAndroid Build Coastguard Worker screen->base.screen->fence_finish(screen->base.screen, ctx->st->pipe,
283*61046927SAndroid Build Coastguard Worker fence, OS_TIMEOUT_INFINITE);
284*61046927SAndroid Build Coastguard Worker screen->base.screen->fence_reference(screen->base.screen, &fence, NULL);
285*61046927SAndroid Build Coastguard Worker drisw_copy_to_front(ctx->st->pipe, drawable, ptex, nrects, nrects ? stack_boxes : NULL);
286*61046927SAndroid Build Coastguard Worker drawable->buffer_age = 1;
287*61046927SAndroid Build Coastguard Worker
288*61046927SAndroid Build Coastguard Worker /* TODO: remove this if the framebuffer state doesn't change. */
289*61046927SAndroid Build Coastguard Worker st_context_invalidate_state(ctx->st, ST_INVALIDATE_FB_STATE);
290*61046927SAndroid Build Coastguard Worker }
291*61046927SAndroid Build Coastguard Worker }
292*61046927SAndroid Build Coastguard Worker
293*61046927SAndroid Build Coastguard Worker static void
drisw_swap_buffers(struct dri_drawable * drawable)294*61046927SAndroid Build Coastguard Worker drisw_swap_buffers(struct dri_drawable *drawable)
295*61046927SAndroid Build Coastguard Worker {
296*61046927SAndroid Build Coastguard Worker drisw_swap_buffers_with_damage(drawable, 0, NULL);
297*61046927SAndroid Build Coastguard Worker }
298*61046927SAndroid Build Coastguard Worker
299*61046927SAndroid Build Coastguard Worker static void
drisw_copy_sub_buffer(struct dri_drawable * drawable,int x,int y,int w,int h)300*61046927SAndroid Build Coastguard Worker drisw_copy_sub_buffer(struct dri_drawable *drawable, int x, int y,
301*61046927SAndroid Build Coastguard Worker int w, int h)
302*61046927SAndroid Build Coastguard Worker {
303*61046927SAndroid Build Coastguard Worker struct dri_context *ctx = dri_get_current();
304*61046927SAndroid Build Coastguard Worker struct dri_screen *screen = drawable->screen;
305*61046927SAndroid Build Coastguard Worker struct pipe_resource *ptex;
306*61046927SAndroid Build Coastguard Worker struct pipe_box box;
307*61046927SAndroid Build Coastguard Worker if (!ctx)
308*61046927SAndroid Build Coastguard Worker return;
309*61046927SAndroid Build Coastguard Worker
310*61046927SAndroid Build Coastguard Worker ptex = drawable->textures[ST_ATTACHMENT_BACK_LEFT];
311*61046927SAndroid Build Coastguard Worker
312*61046927SAndroid Build Coastguard Worker if (ptex) {
313*61046927SAndroid Build Coastguard Worker /* Wait for glthread to finish because we can't use pipe_context from
314*61046927SAndroid Build Coastguard Worker * multiple threads.
315*61046927SAndroid Build Coastguard Worker */
316*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish(ctx->st->ctx);
317*61046927SAndroid Build Coastguard Worker
318*61046927SAndroid Build Coastguard Worker struct pipe_fence_handle *fence = NULL;
319*61046927SAndroid Build Coastguard Worker if (ctx->pp && drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL])
320*61046927SAndroid Build Coastguard Worker pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
321*61046927SAndroid Build Coastguard Worker
322*61046927SAndroid Build Coastguard Worker st_context_flush(ctx->st, ST_FLUSH_FRONT, &fence, NULL, NULL);
323*61046927SAndroid Build Coastguard Worker
324*61046927SAndroid Build Coastguard Worker screen->base.screen->fence_finish(screen->base.screen, ctx->st->pipe,
325*61046927SAndroid Build Coastguard Worker fence, OS_TIMEOUT_INFINITE);
326*61046927SAndroid Build Coastguard Worker screen->base.screen->fence_reference(screen->base.screen, &fence, NULL);
327*61046927SAndroid Build Coastguard Worker
328*61046927SAndroid Build Coastguard Worker if (drawable->stvis.samples > 1) {
329*61046927SAndroid Build Coastguard Worker /* Resolve the back buffer. */
330*61046927SAndroid Build Coastguard Worker dri_pipe_blit(ctx->st->pipe,
331*61046927SAndroid Build Coastguard Worker drawable->textures[ST_ATTACHMENT_BACK_LEFT],
332*61046927SAndroid Build Coastguard Worker drawable->msaa_textures[ST_ATTACHMENT_BACK_LEFT]);
333*61046927SAndroid Build Coastguard Worker }
334*61046927SAndroid Build Coastguard Worker
335*61046927SAndroid Build Coastguard Worker u_box_2d(x, drawable->h - y - h, w, h, &box);
336*61046927SAndroid Build Coastguard Worker drisw_present_texture(ctx->st->pipe, drawable, ptex, 1, &box);
337*61046927SAndroid Build Coastguard Worker }
338*61046927SAndroid Build Coastguard Worker }
339*61046927SAndroid Build Coastguard Worker
340*61046927SAndroid Build Coastguard Worker static bool
drisw_flush_frontbuffer(struct dri_context * ctx,struct dri_drawable * drawable,enum st_attachment_type statt)341*61046927SAndroid Build Coastguard Worker drisw_flush_frontbuffer(struct dri_context *ctx,
342*61046927SAndroid Build Coastguard Worker struct dri_drawable *drawable,
343*61046927SAndroid Build Coastguard Worker enum st_attachment_type statt)
344*61046927SAndroid Build Coastguard Worker {
345*61046927SAndroid Build Coastguard Worker struct pipe_resource *ptex;
346*61046927SAndroid Build Coastguard Worker
347*61046927SAndroid Build Coastguard Worker if (!ctx || statt != ST_ATTACHMENT_FRONT_LEFT)
348*61046927SAndroid Build Coastguard Worker return false;
349*61046927SAndroid Build Coastguard Worker
350*61046927SAndroid Build Coastguard Worker /* Wait for glthread to finish because we can't use pipe_context from
351*61046927SAndroid Build Coastguard Worker * multiple threads.
352*61046927SAndroid Build Coastguard Worker */
353*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish(ctx->st->ctx);
354*61046927SAndroid Build Coastguard Worker
355*61046927SAndroid Build Coastguard Worker if (drawable->stvis.samples > 1) {
356*61046927SAndroid Build Coastguard Worker /* Resolve the front buffer. */
357*61046927SAndroid Build Coastguard Worker dri_pipe_blit(ctx->st->pipe,
358*61046927SAndroid Build Coastguard Worker drawable->textures[ST_ATTACHMENT_FRONT_LEFT],
359*61046927SAndroid Build Coastguard Worker drawable->msaa_textures[ST_ATTACHMENT_FRONT_LEFT]);
360*61046927SAndroid Build Coastguard Worker }
361*61046927SAndroid Build Coastguard Worker ptex = drawable->textures[statt];
362*61046927SAndroid Build Coastguard Worker
363*61046927SAndroid Build Coastguard Worker if (ptex) {
364*61046927SAndroid Build Coastguard Worker drisw_copy_to_front(ctx->st->pipe, ctx->draw, ptex, 0, NULL);
365*61046927SAndroid Build Coastguard Worker }
366*61046927SAndroid Build Coastguard Worker
367*61046927SAndroid Build Coastguard Worker return true;
368*61046927SAndroid Build Coastguard Worker }
369*61046927SAndroid Build Coastguard Worker
370*61046927SAndroid Build Coastguard Worker extern bool
371*61046927SAndroid Build Coastguard Worker dri_image_drawable_get_buffers(struct dri_drawable *drawable,
372*61046927SAndroid Build Coastguard Worker struct __DRIimageList *images,
373*61046927SAndroid Build Coastguard Worker const enum st_attachment_type *statts,
374*61046927SAndroid Build Coastguard Worker unsigned statts_count);
375*61046927SAndroid Build Coastguard Worker
376*61046927SAndroid Build Coastguard Worker static void
handle_in_fence(struct dri_context * ctx,__DRIimage * img)377*61046927SAndroid Build Coastguard Worker handle_in_fence(struct dri_context *ctx, __DRIimage *img)
378*61046927SAndroid Build Coastguard Worker {
379*61046927SAndroid Build Coastguard Worker struct pipe_context *pipe = ctx->st->pipe;
380*61046927SAndroid Build Coastguard Worker struct pipe_fence_handle *fence;
381*61046927SAndroid Build Coastguard Worker int fd = img->in_fence_fd;
382*61046927SAndroid Build Coastguard Worker
383*61046927SAndroid Build Coastguard Worker if (fd == -1)
384*61046927SAndroid Build Coastguard Worker return;
385*61046927SAndroid Build Coastguard Worker
386*61046927SAndroid Build Coastguard Worker validate_fence_fd(fd);
387*61046927SAndroid Build Coastguard Worker
388*61046927SAndroid Build Coastguard Worker img->in_fence_fd = -1;
389*61046927SAndroid Build Coastguard Worker
390*61046927SAndroid Build Coastguard Worker pipe->create_fence_fd(pipe, &fence, fd, PIPE_FD_TYPE_NATIVE_SYNC);
391*61046927SAndroid Build Coastguard Worker pipe->fence_server_sync(pipe, fence);
392*61046927SAndroid Build Coastguard Worker pipe->screen->fence_reference(pipe->screen, &fence, NULL);
393*61046927SAndroid Build Coastguard Worker
394*61046927SAndroid Build Coastguard Worker close(fd);
395*61046927SAndroid Build Coastguard Worker }
396*61046927SAndroid Build Coastguard Worker
397*61046927SAndroid Build Coastguard Worker /**
398*61046927SAndroid Build Coastguard Worker * Allocate framebuffer attachments.
399*61046927SAndroid Build Coastguard Worker *
400*61046927SAndroid Build Coastguard Worker * During fixed-size operation, the function keeps allocating new attachments
401*61046927SAndroid Build Coastguard Worker * as they are requested. Unused attachments are not removed, not until the
402*61046927SAndroid Build Coastguard Worker * framebuffer is resized or destroyed.
403*61046927SAndroid Build Coastguard Worker */
404*61046927SAndroid Build Coastguard Worker static void
drisw_allocate_textures(struct dri_context * stctx,struct dri_drawable * drawable,const enum st_attachment_type * statts,unsigned count)405*61046927SAndroid Build Coastguard Worker drisw_allocate_textures(struct dri_context *stctx,
406*61046927SAndroid Build Coastguard Worker struct dri_drawable *drawable,
407*61046927SAndroid Build Coastguard Worker const enum st_attachment_type *statts,
408*61046927SAndroid Build Coastguard Worker unsigned count)
409*61046927SAndroid Build Coastguard Worker {
410*61046927SAndroid Build Coastguard Worker struct dri_screen *screen = drawable->screen;
411*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = drawable->screen->swrast_loader;
412*61046927SAndroid Build Coastguard Worker struct pipe_resource templ;
413*61046927SAndroid Build Coastguard Worker unsigned width, height;
414*61046927SAndroid Build Coastguard Worker bool resized;
415*61046927SAndroid Build Coastguard Worker unsigned i;
416*61046927SAndroid Build Coastguard Worker const __DRIimageLoaderExtension *image = screen->image.loader;
417*61046927SAndroid Build Coastguard Worker struct __DRIimageList images;
418*61046927SAndroid Build Coastguard Worker bool imported_buffers = true;
419*61046927SAndroid Build Coastguard Worker
420*61046927SAndroid Build Coastguard Worker /* Wait for glthread to finish because we can't use pipe_context from
421*61046927SAndroid Build Coastguard Worker * multiple threads.
422*61046927SAndroid Build Coastguard Worker */
423*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish(stctx->st->ctx);
424*61046927SAndroid Build Coastguard Worker
425*61046927SAndroid Build Coastguard Worker /* First try to get the buffers from the loader */
426*61046927SAndroid Build Coastguard Worker if (image) {
427*61046927SAndroid Build Coastguard Worker if (!dri_image_drawable_get_buffers(drawable, &images,
428*61046927SAndroid Build Coastguard Worker statts, count))
429*61046927SAndroid Build Coastguard Worker imported_buffers = false;
430*61046927SAndroid Build Coastguard Worker }
431*61046927SAndroid Build Coastguard Worker
432*61046927SAndroid Build Coastguard Worker width = drawable->w;
433*61046927SAndroid Build Coastguard Worker height = drawable->h;
434*61046927SAndroid Build Coastguard Worker
435*61046927SAndroid Build Coastguard Worker resized = (drawable->old_w != width ||
436*61046927SAndroid Build Coastguard Worker drawable->old_h != height);
437*61046927SAndroid Build Coastguard Worker
438*61046927SAndroid Build Coastguard Worker /* remove outdated textures */
439*61046927SAndroid Build Coastguard Worker if (resized) {
440*61046927SAndroid Build Coastguard Worker for (i = 0; i < ST_ATTACHMENT_COUNT; i++) {
441*61046927SAndroid Build Coastguard Worker pipe_resource_reference(&drawable->textures[i], NULL);
442*61046927SAndroid Build Coastguard Worker pipe_resource_reference(&drawable->msaa_textures[i], NULL);
443*61046927SAndroid Build Coastguard Worker }
444*61046927SAndroid Build Coastguard Worker drawable->buffer_age = 0;
445*61046927SAndroid Build Coastguard Worker }
446*61046927SAndroid Build Coastguard Worker
447*61046927SAndroid Build Coastguard Worker memset(&templ, 0, sizeof(templ));
448*61046927SAndroid Build Coastguard Worker templ.target = screen->target;
449*61046927SAndroid Build Coastguard Worker templ.width0 = width;
450*61046927SAndroid Build Coastguard Worker templ.height0 = height;
451*61046927SAndroid Build Coastguard Worker templ.depth0 = 1;
452*61046927SAndroid Build Coastguard Worker templ.array_size = 1;
453*61046927SAndroid Build Coastguard Worker templ.last_level = 0;
454*61046927SAndroid Build Coastguard Worker
455*61046927SAndroid Build Coastguard Worker if (imported_buffers && image) {
456*61046927SAndroid Build Coastguard Worker if (images.image_mask & __DRI_IMAGE_BUFFER_FRONT) {
457*61046927SAndroid Build Coastguard Worker struct pipe_resource **buf =
458*61046927SAndroid Build Coastguard Worker &drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
459*61046927SAndroid Build Coastguard Worker struct pipe_resource *texture = images.front->texture;
460*61046927SAndroid Build Coastguard Worker
461*61046927SAndroid Build Coastguard Worker drawable->w = texture->width0;
462*61046927SAndroid Build Coastguard Worker drawable->h = texture->height0;
463*61046927SAndroid Build Coastguard Worker
464*61046927SAndroid Build Coastguard Worker pipe_resource_reference(buf, texture);
465*61046927SAndroid Build Coastguard Worker handle_in_fence(stctx, images.front);
466*61046927SAndroid Build Coastguard Worker }
467*61046927SAndroid Build Coastguard Worker
468*61046927SAndroid Build Coastguard Worker if (images.image_mask & __DRI_IMAGE_BUFFER_BACK) {
469*61046927SAndroid Build Coastguard Worker struct pipe_resource **buf =
470*61046927SAndroid Build Coastguard Worker &drawable->textures[ST_ATTACHMENT_BACK_LEFT];
471*61046927SAndroid Build Coastguard Worker struct pipe_resource *texture = images.back->texture;
472*61046927SAndroid Build Coastguard Worker
473*61046927SAndroid Build Coastguard Worker drawable->w = texture->width0;
474*61046927SAndroid Build Coastguard Worker drawable->h = texture->height0;
475*61046927SAndroid Build Coastguard Worker
476*61046927SAndroid Build Coastguard Worker pipe_resource_reference(buf, texture);
477*61046927SAndroid Build Coastguard Worker handle_in_fence(stctx, images.back);
478*61046927SAndroid Build Coastguard Worker }
479*61046927SAndroid Build Coastguard Worker
480*61046927SAndroid Build Coastguard Worker if (images.image_mask & __DRI_IMAGE_BUFFER_SHARED) {
481*61046927SAndroid Build Coastguard Worker struct pipe_resource **buf =
482*61046927SAndroid Build Coastguard Worker &drawable->textures[ST_ATTACHMENT_BACK_LEFT];
483*61046927SAndroid Build Coastguard Worker struct pipe_resource *texture = images.back->texture;
484*61046927SAndroid Build Coastguard Worker
485*61046927SAndroid Build Coastguard Worker drawable->w = texture->width0;
486*61046927SAndroid Build Coastguard Worker drawable->h = texture->height0;
487*61046927SAndroid Build Coastguard Worker
488*61046927SAndroid Build Coastguard Worker pipe_resource_reference(buf, texture);
489*61046927SAndroid Build Coastguard Worker handle_in_fence(stctx, images.back);
490*61046927SAndroid Build Coastguard Worker }
491*61046927SAndroid Build Coastguard Worker
492*61046927SAndroid Build Coastguard Worker /* Note: if there is both a back and a front buffer,
493*61046927SAndroid Build Coastguard Worker * then they have the same size.
494*61046927SAndroid Build Coastguard Worker */
495*61046927SAndroid Build Coastguard Worker templ.width0 = drawable->w;
496*61046927SAndroid Build Coastguard Worker templ.height0 = drawable->h;
497*61046927SAndroid Build Coastguard Worker } else {
498*61046927SAndroid Build Coastguard Worker for (i = 0; i < count; i++) {
499*61046927SAndroid Build Coastguard Worker enum pipe_format format;
500*61046927SAndroid Build Coastguard Worker unsigned bind;
501*61046927SAndroid Build Coastguard Worker
502*61046927SAndroid Build Coastguard Worker /* the texture already exists or not requested */
503*61046927SAndroid Build Coastguard Worker if (drawable->textures[statts[i]])
504*61046927SAndroid Build Coastguard Worker continue;
505*61046927SAndroid Build Coastguard Worker
506*61046927SAndroid Build Coastguard Worker dri_drawable_get_format(drawable, statts[i], &format, &bind);
507*61046927SAndroid Build Coastguard Worker
508*61046927SAndroid Build Coastguard Worker /* if we don't do any present, no need for display targets */
509*61046927SAndroid Build Coastguard Worker if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !screen->swrast_no_present)
510*61046927SAndroid Build Coastguard Worker bind |= PIPE_BIND_DISPLAY_TARGET;
511*61046927SAndroid Build Coastguard Worker
512*61046927SAndroid Build Coastguard Worker if (format == PIPE_FORMAT_NONE)
513*61046927SAndroid Build Coastguard Worker continue;
514*61046927SAndroid Build Coastguard Worker
515*61046927SAndroid Build Coastguard Worker templ.format = format;
516*61046927SAndroid Build Coastguard Worker templ.bind = bind;
517*61046927SAndroid Build Coastguard Worker templ.nr_samples = 0;
518*61046927SAndroid Build Coastguard Worker templ.nr_storage_samples = 0;
519*61046927SAndroid Build Coastguard Worker
520*61046927SAndroid Build Coastguard Worker if (statts[i] == ST_ATTACHMENT_FRONT_LEFT &&
521*61046927SAndroid Build Coastguard Worker screen->base.screen->resource_create_front &&
522*61046927SAndroid Build Coastguard Worker loader->base.version >= 3) {
523*61046927SAndroid Build Coastguard Worker drawable->textures[statts[i]] =
524*61046927SAndroid Build Coastguard Worker screen->base.screen->resource_create_front(screen->base.screen, &templ, (const void *)drawable);
525*61046927SAndroid Build Coastguard Worker } else
526*61046927SAndroid Build Coastguard Worker drawable->textures[statts[i]] =
527*61046927SAndroid Build Coastguard Worker screen->base.screen->resource_create(screen->base.screen, &templ);
528*61046927SAndroid Build Coastguard Worker
529*61046927SAndroid Build Coastguard Worker if (drawable->stvis.samples > 1) {
530*61046927SAndroid Build Coastguard Worker templ.bind = templ.bind &
531*61046927SAndroid Build Coastguard Worker ~(PIPE_BIND_SCANOUT | PIPE_BIND_SHARED | PIPE_BIND_DISPLAY_TARGET);
532*61046927SAndroid Build Coastguard Worker templ.nr_samples = drawable->stvis.samples;
533*61046927SAndroid Build Coastguard Worker templ.nr_storage_samples = drawable->stvis.samples;
534*61046927SAndroid Build Coastguard Worker drawable->msaa_textures[statts[i]] =
535*61046927SAndroid Build Coastguard Worker screen->base.screen->resource_create(screen->base.screen, &templ);
536*61046927SAndroid Build Coastguard Worker
537*61046927SAndroid Build Coastguard Worker dri_pipe_blit(stctx->st->pipe,
538*61046927SAndroid Build Coastguard Worker drawable->msaa_textures[statts[i]],
539*61046927SAndroid Build Coastguard Worker drawable->textures[statts[i]]);
540*61046927SAndroid Build Coastguard Worker }
541*61046927SAndroid Build Coastguard Worker }
542*61046927SAndroid Build Coastguard Worker }
543*61046927SAndroid Build Coastguard Worker
544*61046927SAndroid Build Coastguard Worker drawable->old_w = width;
545*61046927SAndroid Build Coastguard Worker drawable->old_h = height;
546*61046927SAndroid Build Coastguard Worker }
547*61046927SAndroid Build Coastguard Worker
548*61046927SAndroid Build Coastguard Worker void
drisw_update_tex_buffer(struct dri_drawable * drawable,struct dri_context * ctx,struct pipe_resource * res)549*61046927SAndroid Build Coastguard Worker drisw_update_tex_buffer(struct dri_drawable *drawable,
550*61046927SAndroid Build Coastguard Worker struct dri_context *ctx,
551*61046927SAndroid Build Coastguard Worker struct pipe_resource *res)
552*61046927SAndroid Build Coastguard Worker {
553*61046927SAndroid Build Coastguard Worker struct st_context *st_ctx = (struct st_context *)ctx->st;
554*61046927SAndroid Build Coastguard Worker struct pipe_context *pipe = st_ctx->pipe;
555*61046927SAndroid Build Coastguard Worker struct pipe_transfer *transfer;
556*61046927SAndroid Build Coastguard Worker char *map;
557*61046927SAndroid Build Coastguard Worker int x, y, w, h;
558*61046927SAndroid Build Coastguard Worker int ximage_stride, line;
559*61046927SAndroid Build Coastguard Worker int cpp = util_format_get_blocksize(res->format);
560*61046927SAndroid Build Coastguard Worker
561*61046927SAndroid Build Coastguard Worker /* Wait for glthread to finish because we can't use pipe_context from
562*61046927SAndroid Build Coastguard Worker * multiple threads.
563*61046927SAndroid Build Coastguard Worker */
564*61046927SAndroid Build Coastguard Worker _mesa_glthread_finish(ctx->st->ctx);
565*61046927SAndroid Build Coastguard Worker
566*61046927SAndroid Build Coastguard Worker get_drawable_info(drawable, &x, &y, &w, &h);
567*61046927SAndroid Build Coastguard Worker
568*61046927SAndroid Build Coastguard Worker map = pipe_texture_map(pipe, res,
569*61046927SAndroid Build Coastguard Worker 0, 0, // level, layer,
570*61046927SAndroid Build Coastguard Worker PIPE_MAP_WRITE,
571*61046927SAndroid Build Coastguard Worker x, y, w, h, &transfer);
572*61046927SAndroid Build Coastguard Worker
573*61046927SAndroid Build Coastguard Worker /* Copy the Drawable content to the mapped texture buffer */
574*61046927SAndroid Build Coastguard Worker if (!get_image_shm(drawable, x, y, w, h, res))
575*61046927SAndroid Build Coastguard Worker get_image(drawable, x, y, w, h, map);
576*61046927SAndroid Build Coastguard Worker
577*61046927SAndroid Build Coastguard Worker /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
578*61046927SAndroid Build Coastguard Worker get_image() has a pitch rounded up to 4 bytes. */
579*61046927SAndroid Build Coastguard Worker ximage_stride = ((w * cpp) + 3) & -4;
580*61046927SAndroid Build Coastguard Worker for (line = h-1; line; --line) {
581*61046927SAndroid Build Coastguard Worker memmove(&map[line * transfer->stride],
582*61046927SAndroid Build Coastguard Worker &map[line * ximage_stride],
583*61046927SAndroid Build Coastguard Worker ximage_stride);
584*61046927SAndroid Build Coastguard Worker }
585*61046927SAndroid Build Coastguard Worker
586*61046927SAndroid Build Coastguard Worker pipe_texture_unmap(pipe, transfer);
587*61046927SAndroid Build Coastguard Worker }
588*61046927SAndroid Build Coastguard Worker
589*61046927SAndroid Build Coastguard Worker /*
590*61046927SAndroid Build Coastguard Worker * Backend function for init_screen.
591*61046927SAndroid Build Coastguard Worker */
592*61046927SAndroid Build Coastguard Worker
593*61046927SAndroid Build Coastguard Worker static const struct drisw_loader_funcs drisw_lf = {
594*61046927SAndroid Build Coastguard Worker .get_image = drisw_get_image,
595*61046927SAndroid Build Coastguard Worker .put_image = drisw_put_image,
596*61046927SAndroid Build Coastguard Worker .put_image2 = drisw_put_image2
597*61046927SAndroid Build Coastguard Worker };
598*61046927SAndroid Build Coastguard Worker
599*61046927SAndroid Build Coastguard Worker static const struct drisw_loader_funcs drisw_shm_lf = {
600*61046927SAndroid Build Coastguard Worker .get_image = drisw_get_image,
601*61046927SAndroid Build Coastguard Worker .put_image = drisw_put_image,
602*61046927SAndroid Build Coastguard Worker .put_image2 = drisw_put_image2,
603*61046927SAndroid Build Coastguard Worker .put_image_shm = drisw_put_image_shm
604*61046927SAndroid Build Coastguard Worker };
605*61046927SAndroid Build Coastguard Worker
606*61046927SAndroid Build Coastguard Worker void
drisw_init_drawable(struct dri_drawable * drawable,bool isPixmap,int alphaBits)607*61046927SAndroid Build Coastguard Worker drisw_init_drawable(struct dri_drawable *drawable, bool isPixmap, int alphaBits)
608*61046927SAndroid Build Coastguard Worker {
609*61046927SAndroid Build Coastguard Worker drawable->allocate_textures = drisw_allocate_textures;
610*61046927SAndroid Build Coastguard Worker drawable->update_drawable_info = drisw_update_drawable_info;
611*61046927SAndroid Build Coastguard Worker drawable->flush_frontbuffer = drisw_flush_frontbuffer;
612*61046927SAndroid Build Coastguard Worker drawable->update_tex_buffer = drisw_update_tex_buffer;
613*61046927SAndroid Build Coastguard Worker drawable->swap_buffers = drisw_swap_buffers;
614*61046927SAndroid Build Coastguard Worker drawable->swap_buffers_with_damage = drisw_swap_buffers_with_damage;
615*61046927SAndroid Build Coastguard Worker }
616*61046927SAndroid Build Coastguard Worker
617*61046927SAndroid Build Coastguard Worker struct pipe_screen *
drisw_init_screen(struct dri_screen * screen,bool driver_name_is_inferred)618*61046927SAndroid Build Coastguard Worker drisw_init_screen(struct dri_screen *screen, bool driver_name_is_inferred)
619*61046927SAndroid Build Coastguard Worker {
620*61046927SAndroid Build Coastguard Worker const __DRIswrastLoaderExtension *loader = screen->swrast_loader;
621*61046927SAndroid Build Coastguard Worker struct pipe_screen *pscreen = NULL;
622*61046927SAndroid Build Coastguard Worker const struct drisw_loader_funcs *lf = &drisw_lf;
623*61046927SAndroid Build Coastguard Worker
624*61046927SAndroid Build Coastguard Worker screen->swrast_no_present = debug_get_option_swrast_no_present();
625*61046927SAndroid Build Coastguard Worker
626*61046927SAndroid Build Coastguard Worker if (loader->base.version >= 4) {
627*61046927SAndroid Build Coastguard Worker if (loader->putImageShm)
628*61046927SAndroid Build Coastguard Worker lf = &drisw_shm_lf;
629*61046927SAndroid Build Coastguard Worker }
630*61046927SAndroid Build Coastguard Worker
631*61046927SAndroid Build Coastguard Worker bool success = false;
632*61046927SAndroid Build Coastguard Worker #ifdef HAVE_DRISW_KMS
633*61046927SAndroid Build Coastguard Worker if (screen->fd != -1)
634*61046927SAndroid Build Coastguard Worker success = pipe_loader_sw_probe_kms(&screen->dev, screen->fd);
635*61046927SAndroid Build Coastguard Worker #endif
636*61046927SAndroid Build Coastguard Worker if (!success)
637*61046927SAndroid Build Coastguard Worker success = pipe_loader_sw_probe_dri(&screen->dev, lf);
638*61046927SAndroid Build Coastguard Worker
639*61046927SAndroid Build Coastguard Worker if (success)
640*61046927SAndroid Build Coastguard Worker pscreen = pipe_loader_create_screen(screen->dev, driver_name_is_inferred);
641*61046927SAndroid Build Coastguard Worker
642*61046927SAndroid Build Coastguard Worker return pscreen;
643*61046927SAndroid Build Coastguard Worker }
644*61046927SAndroid Build Coastguard Worker
645*61046927SAndroid Build Coastguard Worker /* swrast copy sub buffer entrypoint. */
646*61046927SAndroid Build Coastguard Worker void
driswCopySubBuffer(__DRIdrawable * pdp,int x,int y,int w,int h)647*61046927SAndroid Build Coastguard Worker driswCopySubBuffer(__DRIdrawable *pdp, int x, int y, int w, int h)
648*61046927SAndroid Build Coastguard Worker {
649*61046927SAndroid Build Coastguard Worker struct dri_drawable *drawable = dri_drawable(pdp);
650*61046927SAndroid Build Coastguard Worker
651*61046927SAndroid Build Coastguard Worker assert(drawable->screen->swrast_loader);
652*61046927SAndroid Build Coastguard Worker
653*61046927SAndroid Build Coastguard Worker drisw_copy_sub_buffer(drawable, x, y, w, h);
654*61046927SAndroid Build Coastguard Worker }
655*61046927SAndroid Build Coastguard Worker
656*61046927SAndroid Build Coastguard Worker /* vim: set sw=3 ts=8 sts=3 expandtab: */
657