summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/i915tex/intel_surface.c
blob: 3be902cf9c1055357bf15d4989792392676ca3f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "glheader.h"
#include "context.h"
#include "framebuffer.h"
#include "renderbuffer.h"
#include "utils.h"
#include "main/macros.h"


#include "intel_screen.h"

#include "intel_context.h"
#include "intel_buffers.h"
#include "intel_regions.h"
#include "intel_span.h"
#include "intel_fbo.h"

#include "pipe/p_state.h"
#include "pipe/p_defines.h"
#include "pipe/softpipe/sp_surface.h"


/*
 * XXX a lof of this is a temporary kludge
 */



static void
read_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
                GLfloat (*rrrr)[QUAD_SIZE])
{
   struct intel_surface *is = (struct intel_surface *) sps;
   struct intel_renderbuffer *irb = is->rb;
   const GLubyte *src = (const GLubyte *) irb->region->map
      + (y * irb->region->pitch + x) * irb->region->cpp;
   GLfloat *dst = (GLfloat *) rrrr;
   GLubyte temp[16];
   GLuint i, j;

   memcpy(temp, src, 8);
   memcpy(temp + 8, src + irb->region->pitch * irb->region->cpp, 8);

   for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
         dst[j * 4 + i] = UBYTE_TO_FLOAT(temp[i * 4 + j]);
      }
   }
}


static void
write_quad_f_swz(struct softpipe_surface *sps, GLint x, GLint y,
                 GLfloat (*rrrr)[QUAD_SIZE])
{
   struct intel_surface *is = (struct intel_surface *) sps;
   struct intel_renderbuffer *irb = is->rb;
   const GLfloat *src = (const GLfloat *) rrrr;
   GLubyte *dst = (GLubyte *) irb->region->map
      + (y * irb->region->pitch + x) * irb->region->cpp;
   GLubyte temp[16];
   GLuint i, j;

   for (i = 0; i < 4; i++) {
      for (j = 0; j < 4; j++) {
         UNCLAMPED_FLOAT_TO_UBYTE(temp[j * 4 + i], src[i * 4 + j]);
      }
   }

   memcpy(dst, temp, 8);
   memcpy(dst + irb->region->pitch * irb->region->cpp, temp + 8, 8);
}



static void *
map_surface_buffer(struct pipe_buffer *pb, GLuint access_mode)
{
   struct intel_surface *is = (struct intel_surface *) pb;
   struct intel_renderbuffer *irb = is->rb;
   GET_CURRENT_CONTEXT(ctx);
   struct intel_context *intel = intel_context(ctx);

   assert(access_mode == PIPE_MAP_READ_WRITE);

   intelFinish(&intel->ctx);

   /*LOCK_HARDWARE(intel);*/

   if (irb->region) {
      intel_region_map(intel->intelScreen, irb->region);
   }
   pb->ptr = irb->region->map;

   return pb->ptr;
}


static void
unmap_surface_buffer(struct pipe_buffer *pb)
{
   struct intel_surface *is = (struct intel_surface *) pb;
   struct intel_renderbuffer *irb = is->rb;
   GET_CURRENT_CONTEXT(ctx);
   struct intel_context *intel = intel_context(ctx);

   if (irb->region) {
      intel_region_unmap(intel->intelScreen, irb->region);
   }
   pb->ptr = NULL;

   /*UNLOCK_HARDWARE(intel);*/
}


struct pipe_surface *
xmesa_get_color_surface(GLcontext *ctx, GLuint i)
{
   struct intel_context *intel = intel_context(ctx);
   struct intel_framebuffer *intel_fb;
   struct intel_renderbuffer *intel_rb;

   intel_fb = (struct intel_framebuffer *) ctx->DrawBuffer;
   intel_rb = intel_fb->color_rb[1];

   if (!intel_rb->surface) {
      /* create surface and attach to intel_rb */
      struct intel_surface *is;
      is = CALLOC_STRUCT(intel_surface);
      if (is) {
         is->surface.surface.width = intel_rb->Base.Width;
         is->surface.surface.height = intel_rb->Base.Height;

         is->surface.read_quad_f_swz = read_quad_f_swz;
         is->surface.write_quad_f_swz = write_quad_f_swz;

         is->surface.surface.buffer.map = map_surface_buffer;
         is->surface.surface.buffer.unmap = unmap_surface_buffer;

         is->rb = intel_rb;
      }
      intel_rb->surface = is;
   }
   else {
      /* update surface size */
      struct intel_surface *is = intel_rb->surface;
      is->surface.surface.width = intel_rb->Base.Width;
      is->surface.surface.height = intel_rb->Base.Height;
      /* sanity check */
      assert(is->surface.surface.buffer.map == map_surface_buffer);
   }

   return &intel_rb->surface->surface.surface;
}


struct pipe_surface *
xmesa_get_z_surface(GLcontext *ctx)
{
   /* XXX fix */
   return NULL;
}


struct pipe_surface *
xmesa_get_stencil_surface(GLcontext *ctx)
{
   /* XXX fix */
   return NULL;
}