blob: 3331026f66b972e37af1e7cc21d6efa9d340a8be [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:
78 case COPYBIT_FORMAT_RGB_565:
79 case COPYBIT_FORMAT_BGRA_8888:
80 case COPYBIT_FORMAT_RGBA_5551:
81 case COPYBIT_FORMAT_RGBA_4444:
82 case COPYBIT_FORMAT_YCbCr_422_SP:
83 case COPYBIT_FORMAT_YCbCr_420_SP:
84 return true;
85 default:
86 return false;
87 }
88}
89
90static bool hasAlpha(int format) {
91 switch (format) {
92 case COPYBIT_FORMAT_RGBA_8888:
93 case COPYBIT_FORMAT_BGRA_8888:
94 case COPYBIT_FORMAT_RGBA_5551:
95 case COPYBIT_FORMAT_RGBA_4444:
96 return true;
97 default:
98 return false;
99 }
100}
101
102static inline int fixedToByte(GGLfixed val) {
103 return (val - (val >> 8)) >> 8;
104}
105
106/**
107 * Performs a quick check of the rendering state. If this function returns
108 * false we cannot use the copybit driver.
109 */
110
111static bool checkContext(ogles_context_t* c) {
112
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700113 // By convention copybitQuickCheckContext() has already returned true.
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700114 // avoid checking the same information again.
115
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700116 if (c->copybits.blitEngine == NULL) {
117 LOGD_IF(DEBUG_COPYBIT, "no copybit hal");
118 return false;
119 }
120
121 if (c->rasterizer.state.enables
122 & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)) {
123 LOGD_IF(DEBUG_COPYBIT, "depth test and/or fog");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700124 return false;
125 }
126
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700127 // Note: The drawSurfaceBuffer is only set for destination
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700128 // surfaces types that are supported by the hardware and
129 // do not have an alpha channel. So we don't have to re-check that here.
130
131 static const int tmu = 0;
132 texture_unit_t& u(c->textures.tmu[tmu]);
133 EGLTextureObject* textureObject = u.texture;
134
135 if (!supportedCopybitsFormat(textureObject->surface.format)) {
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700136 LOGD_IF(DEBUG_COPYBIT, "texture format not supported");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700137 return false;
138 }
139 return true;
140}
141
142
143static bool copybit(GLint x, GLint y,
144 GLint w, GLint h,
145 EGLTextureObject* textureObject,
146 const GLint* crop_rect,
147 int transform,
148 ogles_context_t* c)
149{
150 // We assume checkContext has already been called and has already
151 // returned true.
152
153 const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
154
155 y = cbSurface.height - (y + h);
156
157 const GLint Ucr = crop_rect[0];
158 const GLint Vcr = crop_rect[1];
159 const GLint Wcr = crop_rect[2];
160 const GLint Hcr = crop_rect[3];
161
Mathias Agopian295eff22009-06-29 16:36:49 -0700162 GLint screen_w = w;
163 GLint screen_h = h;
164 int32_t dsdx = Wcr << 16; // dsdx = ((Wcr/screen_w)/Wt)*Wt
165 int32_t dtdy = Hcr << 16; // dtdy = -((Hcr/screen_h)/Ht)*Ht
Mathias Agopiane7829b82009-06-23 18:31:06 -0700166 if (transform & COPYBIT_TRANSFORM_ROT_90) {
Mathias Agopian295eff22009-06-29 16:36:49 -0700167 swap(screen_w, screen_h);
Mathias Agopiane7829b82009-06-23 18:31:06 -0700168 }
Mathias Agopian295eff22009-06-29 16:36:49 -0700169 if (dsdx!=screen_w || dtdy!=screen_h) {
170 // in most cases the divide is not needed
171 dsdx /= screen_w;
172 dtdy /= screen_h;
173 }
174 dtdy = -dtdy; // see equation of dtdy above
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700175 if (dsdx < c->copybits.minScale || dsdx > c->copybits.maxScale
176 || dtdy < c->copybits.minScale || dtdy > c->copybits.maxScale) {
177 // The requested scale is out of the range the hardware
178 // can support.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700179 LOGD_IF(DEBUG_COPYBIT,
Mathias Agopiane7829b82009-06-23 18:31:06 -0700180 "scale out of range dsdx=%08x (Wcr=%d / w=%d), "
181 "dtdy=%08x (Hcr=%d / h=%d), Ucr=%d, Vcr=%d",
182 dsdx, Wcr, w, dtdy, Hcr, h, Ucr, Vcr);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700183 return false;
184 }
185
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700186 // copybit doesn't say anything about filtering, so we can't
187 // discriminate. On msm7k, copybit will always filter.
188 // the code below handles min/mag filters, we keep it as a reference.
189
190#ifdef MIN_MAG_FILTER
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700191 int32_t texelArea = gglMulx(dtdy, dsdx);
192 if (texelArea < FIXED_ONE && textureObject->mag_filter != GL_LINEAR) {
193 // Non-linear filtering on a texture enlargement.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700194 LOGD_IF(DEBUG_COPYBIT, "mag filter is not GL_LINEAR");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700195 return false;
196 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700197 if (texelArea > FIXED_ONE && textureObject->min_filter != GL_LINEAR) {
198 // Non-linear filtering on an texture shrink.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700199 LOGD_IF(DEBUG_COPYBIT, "min filter is not GL_LINEAR");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700200 return false;
201 }
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700202#endif
203
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700204 const uint32_t enables = c->rasterizer.state.enables;
205 int planeAlpha = 255;
206 static const int tmu = 0;
207 texture_t& tev(c->rasterizer.state.texture[tmu]);
208 bool srcTextureHasAlpha = hasAlpha(textureObject->surface.format);
Mathias Agopiane7829b82009-06-23 18:31:06 -0700209 if (!srcTextureHasAlpha) {
210 planeAlpha = fixedToByte(c->currentColorClamped.a);
211 }
212
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700213 switch (tev.env) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700214 case GGL_REPLACE:
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700215 break;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700216 case GGL_MODULATE:
Mathias Agopiane7829b82009-06-23 18:31:06 -0700217 if (! (c->currentColorClamped.r == FIXED_ONE &&
218 c->currentColorClamped.g == FIXED_ONE &&
219 c->currentColorClamped.b == FIXED_ONE)) {
220 LOGD_IF(DEBUG_COPYBIT,
221 "MODULATE and non white color (%08x, %08x, %08x)",
222 c->currentColorClamped.r,
223 c->currentColorClamped.g,
224 c->currentColorClamped.b);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700225 return false;
226 }
Mathias Agopiane7829b82009-06-23 18:31:06 -0700227 if (srcTextureHasAlpha && c->currentColorClamped.a < FIXED_ONE) {
228 LOGD_IF(DEBUG_COPYBIT,
229 "MODULATE and texture w/alpha and alpha=%08x)",
230 c->currentColorClamped.a);
231 return false;
232 }
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700233 break;
234
235 default:
236 // Incompatible texture environment.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700237 LOGD_IF(DEBUG_COPYBIT, "incompatible texture environment");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700238 return false;
239 }
240
241 bool blending = false;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700242 if ((enables & GGL_ENABLE_BLENDING)
243 && !(c->rasterizer.state.blend.src == GL_ONE
244 && c->rasterizer.state.blend.dst == GL_ZERO)) {
245 // Blending is OK if it is
246 // the exact kind of blending that the copybits hardware supports.
247 // Note: The hardware only supports
248 // GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA,
249 // But the surface flinger uses GL_ONE / GL_ONE_MINUS_SRC_ALPHA.
250 // We substitute GL_SRC_ALPHA / GL_ONE_MINUS_SRC_ALPHA in that case,
251 // because the performance is worth it, even if the results are
252 // not correct.
253 if (!((c->rasterizer.state.blend.src == GL_SRC_ALPHA
254 || c->rasterizer.state.blend.src == GL_ONE)
255 && c->rasterizer.state.blend.dst == GL_ONE_MINUS_SRC_ALPHA
256 && c->rasterizer.state.blend.alpha_separate == 0)) {
257 // Incompatible blend mode.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700258 LOGD_IF(DEBUG_COPYBIT, "incompatible blend mode");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700259 return false;
260 }
261 blending = true;
262 } else {
263 // No blending is OK if we are not using alpha.
264 if (srcTextureHasAlpha || planeAlpha != 255) {
265 // Incompatible alpha
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700266 LOGD_IF(DEBUG_COPYBIT, "incompatible alpha");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700267 return false;
268 }
269 }
270
271 if (srcTextureHasAlpha && planeAlpha != 255) {
272 // Can't do two types of alpha at once.
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700273 LOGD_IF(DEBUG_COPYBIT, "src alpha and plane alpha");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700274 return false;
275 }
276
277 // LOGW("calling copybits");
278
279 copybit_device_t* copybit = c->copybits.blitEngine;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700280
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700281 copybit_image_t dst;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700282 buffer_handle_t target_hnd = c->copybits.drawSurfaceBuffer;
283 textureToCopyBitImage(&cbSurface, target_hnd, &dst);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700284 copybit_rect_t drect = {x, y, x+w, y+h};
285
286 copybit_image_t src;
Mathias Agopian0a3139a2009-06-10 16:01:54 -0700287 buffer_handle_t source_hnd = textureObject->buffer->handle;
288 textureToCopyBitImage(&textureObject->surface, source_hnd, &src);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700289 copybit_rect_t srect = { Ucr, Vcr + Hcr, Ucr + Wcr, Vcr };
290
291 copybit->set_parameter(copybit, COPYBIT_TRANSFORM, transform);
292 copybit->set_parameter(copybit, COPYBIT_PLANE_ALPHA, planeAlpha);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700293 copybit->set_parameter(copybit, COPYBIT_DITHER,
294 (enables & GGL_ENABLE_DITHER) ? COPYBIT_ENABLE : COPYBIT_DISABLE);
295
296 clipRectRegion it(c);
Mathias Agopian295eff22009-06-29 16:36:49 -0700297 status_t err = copybit->stretch(copybit, &dst, &src, &drect, &srect, &it);
298 return err == NO_ERROR ? true : false;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700299}
300
301/*
302 * Try to draw a triangle fan with copybit, return false if we fail.
303 */
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700304bool drawTriangleFanWithCopybit_impl(ogles_context_t* c, GLint first, GLsizei count)
305{
306 if (!checkContext(c)) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700307 return false;
308 }
309
Mathias Agopian7272add2009-06-18 19:31:07 -0700310 // FIXME: we should handle culling here
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700311 c->arrays.compileElements(c, c->vc.vBuffer, 0, 4);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700312
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700313 // we detect if we're dealing with a rectangle, by comparing the
314 // rectangles {v0,v2} and {v1,v3} which should be identical.
315
Mathias Agopianaa6e88b2009-06-17 21:58:18 -0700316 // NOTE: we should check that the rectangle is window aligned, however
317 // if we do that, the optimization won't be taken in a lot of cases.
318 // Since this code is intended to be used with SurfaceFlinger only,
319 // so it's okay...
320
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700321 const vec4_t& v0 = c->vc.vBuffer[0].window;
322 const vec4_t& v1 = c->vc.vBuffer[1].window;
323 const vec4_t& v2 = c->vc.vBuffer[2].window;
324 const vec4_t& v3 = c->vc.vBuffer[3].window;
325 int l = min(v0.x, v2.x);
326 int b = min(v0.y, v2.y);
327 int r = max(v0.x, v2.x);
328 int t = max(v0.y, v2.y);
329 if ((l != min(v1.x, v3.x)) || (b != min(v1.y, v3.y)) ||
330 (r != max(v1.x, v3.x)) || (t != max(v1.y, v3.y))) {
331 LOGD_IF(DEBUG_COPYBIT, "geometry not a rectangle");
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700332 return false;
333 }
Mathias Agopian7272add2009-06-18 19:31:07 -0700334
335 // fetch and transform texture coordinates
336 // NOTE: maybe it would be better to have a "compileElementsAll" method
337 // that would ensure all vertex data are fetched and transformed
338 const transform_t& tr = c->transforms.texture[0].transform;
339 for (size_t i=0 ; i<4 ; i++) {
340 const GLubyte* tp = c->arrays.texture[0].element(i);
341 vertex_t* const v = &c->vc.vBuffer[i];
342 c->arrays.texture[0].fetch(c, v->texture[0].v, tp);
343 // FIXME: we should bail if q!=1
344 c->arrays.tex_transform[0](&tr, &v->texture[0], &v->texture[0]);
345 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700346
347 const vec4_t& t0 = c->vc.vBuffer[0].texture[0];
348 const vec4_t& t1 = c->vc.vBuffer[1].texture[0];
349 const vec4_t& t2 = c->vc.vBuffer[2].texture[0];
350 const vec4_t& t3 = c->vc.vBuffer[3].texture[0];
351 int txl = min(t0.x, t2.x);
352 int txb = min(t0.y, t2.y);
353 int txr = max(t0.x, t2.x);
354 int txt = max(t0.y, t2.y);
355 if ((txl != min(t1.x, t3.x)) || (txb != min(t1.y, t3.y)) ||
356 (txr != max(t1.x, t3.x)) || (txt != max(t1.y, t3.y))) {
357 LOGD_IF(DEBUG_COPYBIT, "texcoord not a rectangle");
358 return false;
359 }
360 if ((txl != 0) || (txb != 0) ||
361 (txr != FIXED_ONE) || (txt != FIXED_ONE)) {
362 // we could probably handle this case, if we wanted to
Mathias Agopian7272add2009-06-18 19:31:07 -0700363 LOGD_IF(DEBUG_COPYBIT, "texture is cropped: %08x,%08x,%08x,%08x",
364 txl, txb, txr, txt);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700365 return false;
366 }
367
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700368 // at this point, we know we are dealing with a rectangle, so we
369 // only need to consider 3 vertices for computing the jacobians
370
371 const int dx01 = v1.x - v0.x;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700372 const int dx02 = v2.x - v0.x;
Mathias Agopian295eff22009-06-29 16:36:49 -0700373 const int dy01 = v1.y - v0.y;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700374 const int dy02 = v2.y - v0.y;
375 const int ds01 = t1.S - t0.S;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700376 const int ds02 = t2.S - t0.S;
Mathias Agopian295eff22009-06-29 16:36:49 -0700377 const int dt01 = t1.T - t0.T;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700378 const int dt02 = t2.T - t0.T;
379 const int area = dx01*dy02 - dy01*dx02;
380 int dsdx, dsdy, dtdx, dtdy;
381 if (area >= 0) {
382 dsdx = ds01*dy02 - ds02*dy01;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700383 dtdx = dt01*dy02 - dt02*dy01;
Mathias Agopian295eff22009-06-29 16:36:49 -0700384 dsdy = ds02*dx01 - ds01*dx02;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700385 dtdy = dt02*dx01 - dt01*dx02;
386 } else {
387 dsdx = ds02*dy01 - ds01*dy02;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700388 dtdx = dt02*dy01 - dt01*dy02;
Mathias Agopian295eff22009-06-29 16:36:49 -0700389 dsdy = ds01*dx02 - ds02*dx01;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700390 dtdy = dt01*dx02 - dt02*dx01;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700391 }
392
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700393 // here we rely on the fact that we know the transform is
394 // a rigid-body transform AND that it can only rotate in 90 degrees
395 // increments
396
397 int transform = 0;
398 if (dsdx == 0) {
399 // 90 deg rotation case
400 // [ 0 dtdx ]
401 // [ dsdx 0 ]
402 transform |= COPYBIT_TRANSFORM_ROT_90;
403 // FIXME: not sure if FLIP_H and FLIP_V shouldn't be inverted
404 if (dtdx > 0)
405 transform |= COPYBIT_TRANSFORM_FLIP_H;
406 if (dsdy < 0)
407 transform |= COPYBIT_TRANSFORM_FLIP_V;
408 } else {
409 // [ dsdx 0 ]
410 // [ 0 dtdy ]
411 if (dsdx < 0)
412 transform |= COPYBIT_TRANSFORM_FLIP_H;
413 if (dtdy < 0)
414 transform |= COPYBIT_TRANSFORM_FLIP_V;
415 }
416
417 //LOGD("l=%d, b=%d, w=%d, h=%d, tr=%d", x, y, w, h, transform);
418 //LOGD("A=%f\tB=%f\nC=%f\tD=%f",
419 // dsdx/65536.0, dtdx/65536.0, dsdy/65536.0, dtdy/65536.0);
420
421 int x = l >> 4;
422 int y = b >> 4;
423 int w = (r-l) >> 4;
424 int h = (t-b) >> 4;
425 texture_unit_t& u(c->textures.tmu[0]);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700426 EGLTextureObject* textureObject = u.texture;
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700427 GLint tWidth = textureObject->surface.width;
428 GLint tHeight = textureObject->surface.height;
429 GLint crop_rect[4] = {0, tHeight, tWidth, -tHeight};
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700430 const GGLSurface& cbSurface = c->rasterizer.state.buffers.color.s;
431 y = cbSurface.height - (y + h);
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700432 return copybit(x, y, w, h, textureObject, crop_rect, transform, c);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700433}
434
435/*
436 * Try to drawTexiOESWithCopybit, return false if we fail.
437 */
438
439bool drawTexiOESWithCopybit_impl(GLint x, GLint y, GLint z,
440 GLint w, GLint h, ogles_context_t* c)
441{
442 // quickly process empty rects
443 if ((w|h) <= 0) {
444 return true;
445 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700446 if (!checkContext(c)) {
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700447 return false;
448 }
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700449 texture_unit_t& u(c->textures.tmu[0]);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700450 EGLTextureObject* textureObject = u.texture;
Mathias Agopian6d2cad22009-06-17 21:18:56 -0700451 return copybit(x, y, w, h, textureObject, textureObject->crop_rect, 0, c);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700452}
453
454} // namespace android
455