blob: 867459d64881399b28512573685c8b68a2f62357 [file] [log] [blame]
Mathias Agopian076b1cc2009-04-10 14:24:30 -07001/*
2**
3** Copyright 2009, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include <stdlib.h>
19#include <stdio.h>
20
21#include "context.h"
22#include "fp.h"
23#include "state.h"
24#include "matrix.h"
25#include "vertex.h"
26#include "light.h"
27#include "primitives.h"
28#include "texture.h"
29#include "BufferObjectManager.h"
Mathias Agopian076b1cc2009-04-10 14:24:30 -070030#include "TextureObjectManager.h"
Mathias Agopian0a3139a2009-06-10 16:01:54 -070031
Mathias Agopian076b1cc2009-04-10 14:24:30 -070032#include <hardware/gralloc.h>
33#include <hardware/copybit.h>
Mathias Agopian0a3139a2009-06-10 16:01:54 -070034#include <private/ui/android_natives_priv.h>
Mathias Agopian076b1cc2009-04-10 14:24:30 -070035
Mathias Agopian6d2cad22009-06-17 21:18:56 -070036
37#define DEBUG_COPYBIT true
38
Mathias Agopian076b1cc2009-04-10 14:24:30 -070039// ----------------------------------------------------------------------------
40
41namespace android {
42
Mathias Agopian0a3139a2009-06-10 16:01:54 -070043static void textureToCopyBitImage(
44 const GGLSurface* surface, buffer_handle_t buffer, copybit_image_t* img)
45{
Mathias Agopian076b1cc2009-04-10 14:24:30 -070046 img->w = surface->stride;
47 img->h = surface->height;
48 img->format = surface->format;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070049 img->base = surface->data;
Mathias Agopian5911aa92009-06-24 16:55:59 -070050 img->handle = (native_handle_t *)buffer;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070051}
52
53struct clipRectRegion : public copybit_region_t {
Mathias Agopiancf251b92009-06-16 18:08:29 -070054 clipRectRegion(ogles_context_t* c)
55 {
56 scissor_t const* scissor = &c->rasterizer.state.scissor;
57 r.l = scissor->left;
58 r.t = scissor->top;
59 r.r = scissor->right;
60 r.b = scissor->bottom;
61 next = iterate;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070062 }
63private:
64 static int iterate(copybit_region_t const * self, copybit_rect_t* rect) {
Mathias Agopiancf251b92009-06-16 18:08:29 -070065 *rect = static_cast<clipRectRegion const*>(self)->r;
66 const_cast<copybit_region_t *>(self)->next = iterate_done;
67 return 1;
68 }
69 static int iterate_done(copybit_region_t const *, copybit_rect_t*) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -070070 return 0;
71 }
Mathias Agopiancf251b92009-06-16 18:08:29 -070072 copybit_rect_t r;
Mathias Agopian076b1cc2009-04-10 14:24:30 -070073};
74
75static bool supportedCopybitsFormat(int format) {
76 switch (format) {
77 case COPYBIT_FORMAT_RGBA_8888:
Mathias Agopiandfbec0e2009-08-07 20:55:14 -070078 case COPYBIT_FORMAT_RGBX_8888:
79 case COPYBIT_FORMAT_RGB_888:
Mathias Agopian076b1cc2009-04-10 14:24:30 -070080 case COPYBIT_FORMAT_RGB_565:
81 case COPYBIT_FORMAT_BGRA_8888:
82 case COPYBIT_FORMAT_RGBA_5551:
83 case COPYBIT_FORMAT_RGBA_4444:
84 case COPYBIT_FORMAT_YCbCr_422_SP:
85 case COPYBIT_FORMAT_YCbCr_420_SP:
86 return true;
87 default:
88 return false;
89 }
90}
91
92static bool hasAlpha(int format) {
93 switch (format) {
94 case COPYBIT_FORMAT_RGBA_8888:
95 case COPYBIT_FORMAT_BGRA_8888:
96 case COPYBIT_FORMAT_RGBA_5551:
97 case COPYBIT_FORMAT_RGBA_4444:
98 return true;
99 default:
100 return false;
101 }
102}
103
104static inline int fixedToByte(GGLfixed val) {
105 return (val - (val >> 8)) >> 8;
106}
107
108/**
109 * Performs a quick check of the rendering state. If this function returns
110 * false we cannot use the copybit driver.
111 */
112
113static bool checkContext(ogles_context_t* c) {
114
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700115 // By convention copybitQuickCheckContext() has already returned true.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700116 // avoid checking the same information again.
117
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700118 if (c->copybits.blitEngine == NULL) {
119 LOGD_IF(DEBUG_COPYBIT, "no copybit hal");
120 return false;
121 }
122
123 if (c->rasterizer.state.enables
124 & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)) {
125 LOGD_IF(DEBUG_COPYBIT, "depth test and/or fog");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700126 return false;
127 }
128
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700129 // Note: The drawSurfaceBuffer is only set for destination
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700130 // surfaces types that are supported by the hardware and
131 // do not have an alpha channel. So we don't have to re-check that here.
132
133 static const int tmu = 0;
134 texture_unit_t& u(c->textures.tmu[tmu]);
135 EGLTextureObject* textureObject = u.texture;
136
137 if (!supportedCopybitsFormat(textureObject->surface.format)) {
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700138 LOGD_IF(DEBUG_COPYBIT, "texture format not supported");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700139 return false;
140 }
141 return true;
142}
143
144
145static bool copybit(GLint x, GLint y,
146 GLint w, GLint h,
147 EGLTextureObject* textureObject,
148 const GLint* crop_rect,
149 int transform,
150 ogles_context_t* c)
151{
152 // We assume checkContext has already been called and has already
153 // returned true.
154
155 const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
156
157 y = cbSurface.height - (y + h);
158
159 const GLint Ucr = crop_rect[0];
160 const GLint Vcr = crop_rect[1];
161 const GLint Wcr = crop_rect[2];
162 const GLint Hcr = crop_rect[3];
163
Mathias Agopian295eff22009-06-29 16:36:49 -0700164 GLint screen_w = w;
165 GLint screen_h = h;
166 int32_t dsdx = Wcr << 16; // dsdx = ((Wcr/screen_w)/Wt)*Wt
167 int32_t dtdy = Hcr << 16; // dtdy = -((Hcr/screen_h)/Ht)*Ht
Mathias Agopiane7829b82009-06-23 18:31:06 -0700168 if (transform & COPYBIT_TRANSFORM_ROT_90) {
Mathias Agopian295eff22009-06-29 16:36:49 -0700169 swap(screen_w, screen_h);
Mathias Agopiane7829b82009-06-23 18:31:06 -0700170 }
Mathias Agopian295eff22009-06-29 16:36:49 -0700171 if (dsdx!=screen_w || dtdy!=screen_h) {
172 // in most cases the divide is not needed
173 dsdx /= screen_w;
174 dtdy /= screen_h;
175 }
176 dtdy = -dtdy; // see equation of dtdy above
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700177 if (dsdx < c->copybits.minScale || dsdx > c->copybits.maxScale
178 || dtdy < c->copybits.minScale || dtdy > c->copybits.maxScale) {
179 // The requested scale is out of the range the hardware
180 // can support.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700181 LOGD_IF(DEBUG_COPYBIT,
Mathias Agopiane7829b82009-06-23 18:31:06 -0700182 "scale out of range dsdx=%08x (Wcr=%d / w=%d), "
183 "dtdy=%08x (Hcr=%d / h=%d), Ucr=%d, Vcr=%d",
184 dsdx, Wcr, w, dtdy, Hcr, h, Ucr, Vcr);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700185 return false;
186 }
187
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700188 // copybit doesn't say anything about filtering, so we can't
189 // discriminate. On msm7k, copybit will always filter.
190 // the code below handles min/mag filters, we keep it as a reference.
191
192#ifdef MIN_MAG_FILTER
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700193 int32_t texelArea = gglMulx(dtdy, dsdx);
194 if (texelArea < FIXED_ONE && textureObject->mag_filter != GL_LINEAR) {
195 // Non-linear filtering on a texture enlargement.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700196 LOGD_IF(DEBUG_COPYBIT, "mag filter is not GL_LINEAR");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700197 return false;
198 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700199 if (texelArea > FIXED_ONE && textureObject->min_filter != GL_LINEAR) {
200 // Non-linear filtering on an texture shrink.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700201 LOGD_IF(DEBUG_COPYBIT, "min filter is not GL_LINEAR");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700202 return false;
203 }
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700204#endif
205
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700206 const uint32_t enables = c->rasterizer.state.enables;
207 int planeAlpha = 255;
208 static const int tmu = 0;
209 texture_t& tev(c->rasterizer.state.texture[tmu]);
210 bool srcTextureHasAlpha = hasAlpha(textureObject->surface.format);
Mathias Agopiane7829b82009-06-23 18:31:06 -0700211 if (!srcTextureHasAlpha) {
212 planeAlpha = fixedToByte(c->currentColorClamped.a);
213 }
214
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700215 switch (tev.env) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700216 case GGL_REPLACE:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700217 break;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700218 case GGL_MODULATE:
Mathias Agopiane7829b82009-06-23 18:31:06 -0700219 if (! (c->currentColorClamped.r == FIXED_ONE &&
220 c->currentColorClamped.g == FIXED_ONE &&
221 c->currentColorClamped.b == FIXED_ONE)) {
222 LOGD_IF(DEBUG_COPYBIT,
223 "MODULATE and non white color (%08x, %08x, %08x)",
224 c->currentColorClamped.r,
225 c->currentColorClamped.g,
226 c->currentColorClamped.b);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700227 return false;
228 }
Mathias Agopiane7829b82009-06-23 18:31:06 -0700229 if (srcTextureHasAlpha && c->currentColorClamped.a < FIXED_ONE) {
230 LOGD_IF(DEBUG_COPYBIT,
231 "MODULATE and texture w/alpha and alpha=%08x)",
232 c->currentColorClamped.a);
233 return false;
234 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700235 break;
236
237 default:
238 // Incompatible texture environment.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700239 LOGD_IF(DEBUG_COPYBIT, "incompatible texture environment");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700240 return false;
241 }
242
243 bool blending = false;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700244 if ((enables & GGL_ENABLE_BLENDING)
245 && !(c->rasterizer.state.blend.src == GL_ONE
246 && c->rasterizer.state.blend.dst == GL_ZERO)) {
247 // Blending is OK if it is
248 // the exact kind of blending that the copybits hardware supports.
249 // Note: The hardware only supports
250 // GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA,
251 // But the surface flinger uses GL_ONE / GL_ONE_MINUS_SRC_ALPHA.
252 // We substitute GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA in that case,
253 // because the performance is worth it, even if the results are
254 // not correct.
255 if (!((c->rasterizer.state.blend.src == GL_SRC_ALPHA
256 || c->rasterizer.state.blend.src == GL_ONE)
257 && c->rasterizer.state.blend.dst == GL_ONE_MINUS_SRC_ALPHA
258 && c->rasterizer.state.blend.alpha_separate == 0)) {
259 // Incompatible blend mode.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700260 LOGD_IF(DEBUG_COPYBIT, "incompatible blend mode");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700261 return false;
262 }
263 blending = true;
264 } else {
265 // No blending is OK if we are not using alpha.
266 if (srcTextureHasAlpha || planeAlpha != 255) {
267 // Incompatible alpha
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700268 LOGD_IF(DEBUG_COPYBIT, "incompatible alpha");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700269 return false;
270 }
271 }
272
273 if (srcTextureHasAlpha && planeAlpha != 255) {
274 // Can't do two types of alpha at once.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700275 LOGD_IF(DEBUG_COPYBIT, "src alpha and plane alpha");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700276 return false;
277 }
278
279 // LOGW("calling copybits");
280
281 copybit_device_t* copybit = c->copybits.blitEngine;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700282
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700283 copybit_image_t dst;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700284 buffer_handle_t target_hnd = c->copybits.drawSurfaceBuffer;
285 textureToCopyBitImage(&cbSurface, target_hnd, &dst);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700286 copybit_rect_t drect = {x, y, x+w, y+h};
287
288 copybit_image_t src;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700289 buffer_handle_t source_hnd = textureObject->buffer->handle;
290 textureToCopyBitImage(&textureObject->surface, source_hnd, &src);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700291 copybit_rect_t srect = { Ucr, Vcr + Hcr, Ucr + Wcr, Vcr };
292
293 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, transform);
294 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, planeAlpha);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700295 copybit->set_parameter(copybit, COPYBIT_DITHER,
296 (enables & GGL_ENABLE_DITHER) ? COPYBIT_ENABLE : COPYBIT_DISABLE);
297
298 clipRectRegion it(c);
Mathias Agopian295eff22009-06-29 16:36:49 -0700299 status_t err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
Mathias Agopianf13901e2009-07-15 18:53:32 -0700300 if (err != NO_ERROR) {
301 c->textures.tmu[0].texture->try_copybit = false;
302 }
Mathias Agopian295eff22009-06-29 16:36:49 -0700303 return err == NO_ERROR ? true : false;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700304}
305
306/*
307 * Try to draw a triangle fan with copybit, return false if we fail.
308 */
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700309bool drawTriangleFanWithCopybit_impl(ogles_context_t* c, GLint first, GLsizei count)
310{
311 if (!checkContext(c)) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700312 return false;
313 }
314
Mathias Agopian7272add2009-06-18 19:31:07 -0700315 // FIXME: we should handle culling here
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700316 c->arrays.compileElements(c, c->vc.vBuffer, 0, 4);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700317
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700318 // we detect if we're dealing with a rectangle, by comparing the
319 // rectangles {v0,v2} and {v1,v3} which should be identical.
320
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700321 // NOTE: we should check that the rectangle is window aligned, however
322 // if we do that, the optimization won't be taken in a lot of cases.
323 // Since this code is intended to be used with SurfaceFlinger only,
324 // so it's okay...
325
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700326 const vec4_t& v0 = c->vc.vBuffer[0].window;
327 const vec4_t& v1 = c->vc.vBuffer[1].window;
328 const vec4_t& v2 = c->vc.vBuffer[2].window;
329 const vec4_t& v3 = c->vc.vBuffer[3].window;
330 int l = min(v0.x, v2.x);
331 int b = min(v0.y, v2.y);
332 int r = max(v0.x, v2.x);
333 int t = max(v0.y, v2.y);
334 if ((l != min(v1.x, v3.x)) || (b != min(v1.y, v3.y)) ||
335 (r != max(v1.x, v3.x)) || (t != max(v1.y, v3.y))) {
336 LOGD_IF(DEBUG_COPYBIT, "geometry not a rectangle");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700337 return false;
338 }
Mathias Agopian7272add2009-06-18 19:31:07 -0700339
340 // fetch and transform texture coordinates
341 // NOTE: maybe it would be better to have a "compileElementsAll" method
342 // that would ensure all vertex data are fetched and transformed
343 const transform_t& tr = c->transforms.texture[0].transform;
344 for (size_t i=0 ; i<4 ; i++) {
345 const GLubyte* tp = c->arrays.texture[0].element(i);
346 vertex_t* const v = &c->vc.vBuffer[i];
347 c->arrays.texture[0].fetch(c, v->texture[0].v, tp);
348 // FIXME: we should bail if q!=1
349 c->arrays.tex_transform[0](&tr, &v->texture[0], &v->texture[0]);
350 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700351
352 const vec4_t& t0 = c->vc.vBuffer[0].texture[0];
353 const vec4_t& t1 = c->vc.vBuffer[1].texture[0];
354 const vec4_t& t2 = c->vc.vBuffer[2].texture[0];
355 const vec4_t& t3 = c->vc.vBuffer[3].texture[0];
356 int txl = min(t0.x, t2.x);
357 int txb = min(t0.y, t2.y);
358 int txr = max(t0.x, t2.x);
359 int txt = max(t0.y, t2.y);
360 if ((txl != min(t1.x, t3.x)) || (txb != min(t1.y, t3.y)) ||
361 (txr != max(t1.x, t3.x)) || (txt != max(t1.y, t3.y))) {
362 LOGD_IF(DEBUG_COPYBIT, "texcoord not a rectangle");
363 return false;
364 }
365 if ((txl != 0) || (txb != 0) ||
366 (txr != FIXED_ONE) || (txt != FIXED_ONE)) {
367 // we could probably handle this case, if we wanted to
Mathias Agopian7272add2009-06-18 19:31:07 -0700368 LOGD_IF(DEBUG_COPYBIT, "texture is cropped: %08x,%08x,%08x,%08x",
369 txl, txb, txr, txt);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700370 return false;
371 }
372
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700373 // at this point, we know we are dealing with a rectangle, so we
374 // only need to consider 3 vertices for computing the jacobians
375
376 const int dx01 = v1.x - v0.x;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700377 const int dx02 = v2.x - v0.x;
Mathias Agopian295eff22009-06-29 16:36:49 -0700378 const int dy01 = v1.y - v0.y;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700379 const int dy02 = v2.y - v0.y;
380 const int ds01 = t1.S - t0.S;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700381 const int ds02 = t2.S - t0.S;
Mathias Agopian295eff22009-06-29 16:36:49 -0700382 const int dt01 = t1.T - t0.T;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700383 const int dt02 = t2.T - t0.T;
384 const int area = dx01*dy02 - dy01*dx02;
385 int dsdx, dsdy, dtdx, dtdy;
386 if (area >= 0) {
387 dsdx = ds01*dy02 - ds02*dy01;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700388 dtdx = dt01*dy02 - dt02*dy01;
Mathias Agopian295eff22009-06-29 16:36:49 -0700389 dsdy = ds02*dx01 - ds01*dx02;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700390 dtdy = dt02*dx01 - dt01*dx02;
391 } else {
392 dsdx = ds02*dy01 - ds01*dy02;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700393 dtdx = dt02*dy01 - dt01*dy02;
Mathias Agopian295eff22009-06-29 16:36:49 -0700394 dsdy = ds01*dx02 - ds02*dx01;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700395 dtdy = dt01*dx02 - dt02*dx01;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700396 }
397
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700398 // here we rely on the fact that we know the transform is
399 // a rigid-body transform AND that it can only rotate in 90 degrees
400 // increments
401
402 int transform = 0;
403 if (dsdx == 0) {
404 // 90 deg rotation case
405 // [ 0 dtdx ]
406 // [ dsdx 0 ]
407 transform |= COPYBIT_TRANSFORM_ROT_90;
408 // FIXME: not sure if FLIP_H and FLIP_V shouldn't be inverted
409 if (dtdx > 0)
410 transform |= COPYBIT_TRANSFORM_FLIP_H;
411 if (dsdy < 0)
412 transform |= COPYBIT_TRANSFORM_FLIP_V;
413 } else {
414 // [ dsdx 0 ]
415 // [ 0 dtdy ]
416 if (dsdx < 0)
417 transform |= COPYBIT_TRANSFORM_FLIP_H;
418 if (dtdy < 0)
419 transform |= COPYBIT_TRANSFORM_FLIP_V;
420 }
421
422 //LOGD("l=%d, b=%d, w=%d, h=%d, tr=%d", x, y, w, h, transform);
423 //LOGD("A=%f\tB=%f\nC=%f\tD=%f",
424 // dsdx/65536.0, dtdx/65536.0, dsdy/65536.0, dtdy/65536.0);
425
426 int x = l >> 4;
427 int y = b >> 4;
428 int w = (r-l) >> 4;
429 int h = (t-b) >> 4;
430 texture_unit_t& u(c->textures.tmu[0]);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700431 EGLTextureObject* textureObject = u.texture;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700432 GLint tWidth = textureObject->surface.width;
433 GLint tHeight = textureObject->surface.height;
434 GLint crop_rect[4] = {0, tHeight, tWidth, -tHeight};
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700435 const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
436 y = cbSurface.height - (y + h);
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700437 return copybit(x, y, w, h, textureObject, crop_rect, transform, c);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700438}
439
440/*
441 * Try to drawTexiOESWithCopybit, return false if we fail.
442 */
443
444bool drawTexiOESWithCopybit_impl(GLint x, GLint y, GLint z,
445 GLint w, GLint h, ogles_context_t* c)
446{
447 // quickly process empty rects
448 if ((w|h) <= 0) {
449 return true;
450 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700451 if (!checkContext(c)) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700452 return false;
453 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700454 texture_unit_t& u(c->textures.tmu[0]);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700455 EGLTextureObject* textureObject = u.texture;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700456 return copybit(x, y, w, h, textureObject, textureObject->crop_rect, 0, c);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700457}
458
459} // namespace android
460