1dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/* libs/pixelflinger/scanline.cpp
2dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner** Copyright 2006-2011, The Android Open Source Project
4dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
5dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");
6dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** you may not use this file except in compliance with the License.
7dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** You may obtain a copy of the License at
8dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
9dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**     http://www.apache.org/licenses/LICENSE-2.0
10dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project**
11dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** Unless required by applicable law or agreed to in writing, software
12dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** distributed under the License is distributed on an "AS IS" BASIS,
13dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** See the License for the specific language governing permissions and
15dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project** limitations under the License.
16dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
17dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
18dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
19dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define LOG_TAG "pixelflinger"
20dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
21dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <assert.h>
22dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdlib.h>
23dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <stdio.h>
24dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <string.h>
25dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
26dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <cutils/memory.h>
27dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include <cutils/log.h>
28dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
29dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "buffer.h"
30dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "scanline.h"
31dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
32dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "codeflinger/CodeCache.h"
33dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "codeflinger/GGLAssembler.h"
34dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#include "codeflinger/ARMAssembler.h"
352bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#if defined(__mips__)
362bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#include "codeflinger/MIPSAssembler.h"
372bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#endif
38dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project//#include "codeflinger/ARMAssemblerOptimizer.h"
39dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
40dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
41dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
42dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ANDROID_CODEGEN_GENERIC     0   // force generic pixel pipeline
43dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ANDROID_CODEGEN_C           1   // hand-written C, fallback generic
44dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ANDROID_CODEGEN_ASM         2   // hand-written asm, fallback generic
45dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ANDROID_CODEGEN_GENERATED   3   // hand-written asm, fallback codegen
46dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
47dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#ifdef NDEBUG
48dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_RELEASE
49dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_CODEGEN      ANDROID_CODEGEN_GENERATED
50dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
51dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_DEBUG
52dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_CODEGEN      ANDROID_CODEGEN_GENERATED
53dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
54dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
552bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#if defined(__arm__) || defined(__mips__)
56dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_ARM_CODEGEN  1
57dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
58dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#   define ANDROID_ARM_CODEGEN  0
59dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
60dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
61dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define DEBUG__CODEGEN_ONLY     0
62dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
6339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner/* Set to 1 to dump to the log the states that need a new
6439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * code-generated scanline callback, i.e. those that don't
6539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * have a corresponding shortcut function.
6639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner */
6739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner#define DEBUG_NEEDS  0
68dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
692bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#ifdef __mips__
702bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#define ASSEMBLY_SCRATCH_SIZE   4096
712bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#else
72dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#define ASSEMBLY_SCRATCH_SIZE   2048
732bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#endif
74dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
75dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
76dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectnamespace android {
77dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
78dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
79dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void init_y(context_t*, int32_t);
80dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void init_y_noop(context_t*, int32_t);
81dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void init_y_packed(context_t*, int32_t);
82dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void init_y_error(context_t*, int32_t);
83dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
84dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void step_y__generic(context_t* c);
85dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void step_y__nop(context_t*);
86dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void step_y__smooth(context_t* c);
87dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void step_y__tmu(context_t* c);
88dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void step_y__w(context_t* c);
89dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
90dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline(context_t* c);
91dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_perspective(context_t* c);
92dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_perspective_single(context_t* c);
93dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_t32cb16blend(context_t* c);
9439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_dither(context_t* c);
9539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_srca(context_t* c);
9639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_clamp(context_t* c);
9739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_clamp_dither(context_t* c);
9839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_clamp_mod(context_t* c);
9939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_x32cb16blend_clamp_mod(context_t* c);
10039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16blend_clamp_mod_dither(context_t* c);
10139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_x32cb16blend_clamp_mod_dither(context_t* c);
102dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_t32cb16(context_t* c);
10339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16_dither(context_t* c);
10439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16_clamp(context_t* c);
10539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t32cb16_clamp_dither(context_t* c);
106f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewellstatic void scanline_col32cb16blend(context_t* c);
10739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t16cb16_clamp(context_t* c);
10839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic void scanline_t16cb16blend_clamp_mod(context_t* c);
109dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_memcpy(context_t* c);
110dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_memset8(context_t* c);
111dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_memset16(context_t* c);
112dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_memset32(context_t* c);
113dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_noop(context_t* c);
114dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_set(context_t* c);
115dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void scanline_clear(context_t* c);
116dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
117dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void rect_generic(context_t* c, size_t yc);
118dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void rect_memcpy(context_t* c, size_t yc);
119dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
120068f9f3bf9d09ebca0016cfcbb682d8ca27480f5Duane Sand#if defined( __arm__)
121dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern "C" void scanline_t32cb16blend_arm(uint16_t*, uint32_t*, size_t);
122dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectextern "C" void scanline_t32cb16_arm(uint16_t *dst, uint32_t *src, size_t ct);
123f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewellextern "C" void scanline_col32cb16blend_neon(uint16_t *dst, uint32_t *col, size_t ct);
124f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewellextern "C" void scanline_col32cb16blend_arm(uint16_t *dst, uint32_t col, size_t ct);
125068f9f3bf9d09ebca0016cfcbb682d8ca27480f5Duane Sand#elif defined(__mips__)
126068f9f3bf9d09ebca0016cfcbb682d8ca27480f5Duane Sandextern "C" void scanline_t32cb16blend_mips(uint16_t*, uint32_t*, size_t);
127068f9f3bf9d09ebca0016cfcbb682d8ca27480f5Duane Sand#endif
128dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
129dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
130dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
13139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstatic inline uint16_t  convertAbgr8888ToRgb565(uint32_t  pix)
13239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner{
13339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    return uint16_t( ((pix << 8) & 0xf800) |
13439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner                      ((pix >> 5) & 0x07e0) |
13539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner                      ((pix >> 19) & 0x001f) );
13639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner}
13739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner
138dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstruct shortcut_t {
139dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    needs_filter_t  filter;
140dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const char*     desc;
141dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    void            (*scanline)(context_t*);
142dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    void            (*init_y)(context_t*, int32_t);
143dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
144dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
145dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// Keep in sync with needs
14639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner
14739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner/* To understand the values here, have a look at:
14839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *     system/core/include/private/pixelflinger/ggl_context.h
14939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
15039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * Especially the lines defining and using GGL_RESERVE_NEEDS
15139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
15239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * Quick reminders:
15339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   - the last nibble of the first value is the destination buffer format.
15439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   - the last nibble of the third value is the source texture format
15539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   - formats: 4=rgb565 1=abgr8888 2=xbgr8888
15639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
15739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * In the descriptions below:
15839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
15939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   SRC      means we copy the source pixels to the destination
16039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
16139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   SRC_OVER means we blend the source pixels to the destination
16239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *            with dstFactor = 1-srcA, srcFactor=1  (premultiplied source).
16339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *            This mode is otherwise called 'blend'.
16439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
16539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   SRCA_OVER means we blend the source pixels to the destination
16639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *             with dstFactor=srcA*(1-srcA) srcFactor=srcA (non-premul source).
16739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *             This mode is otherwise called 'blend_srca'
16839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
16939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   clamp    means we fetch source pixels from a texture with u/v clamping
17039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
17139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   mod      means the source pixels are modulated (multiplied) by the
17239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *            a/r/g/b of the current context's color. Typically used for
17339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *            fade-in / fade-out.
17439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
17539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *   dither   means we dither 32 bit values to 16 bits
17639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner */
177dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic shortcut_t shortcuts[] = {
178dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x03515104, 0x00000077, { 0x00000A01, 0x00000000 } },
179dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
18039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, blend SRC_OVER", scanline_t32cb16blend, init_y_noop },
181dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x03010104, 0x00000077, { 0x00000A01, 0x00000000 } },
182dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
18339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC", scanline_t32cb16, init_y_noop  },
18439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* same as first entry, but with dithering */
18539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000177, { 0x00000A01, 0x00000000 } },
18639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
18739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, blend SRC_OVER dither", scanline_t32cb16blend_dither, init_y_noop },
18839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* same as second entry, but with dithering */
18939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000177, { 0x00000A01, 0x00000000 } },
19039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
19139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC dither", scanline_t32cb16_dither, init_y_noop  },
19239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* this is used during the boot animation - CHEAT: ignore dithering */
19339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03545404, 0x00000077, { 0x00000A01, 0x00000000 } },
19439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFEFF, { 0xFFFFFFFF, 0x0000003F } } },
19539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, blend dst:ONE_MINUS_SRCA src:SRCA", scanline_t32cb16blend_srca, init_y_noop },
19639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* special case for arbitrary texture coordinates (think scaling) */
19739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000077, { 0x00000001, 0x00000000 } },
19839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
19939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC_OVER clamp", scanline_t32cb16blend_clamp, init_y },
20039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000177, { 0x00000001, 0x00000000 } },
20139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
20239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC_OVER clamp dither", scanline_t32cb16blend_clamp_dither, init_y },
20339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* another case used during emulation */
20439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000077, { 0x00001001, 0x00000000 } },
20539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
20639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC_OVER clamp modulate", scanline_t32cb16blend_clamp_mod, init_y },
20739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    /* and this */
20839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000077, { 0x00001002, 0x00000000 } },
20939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
21039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, x888 tx, SRC_OVER clamp modulate", scanline_x32cb16blend_clamp_mod, init_y },
21139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000177, { 0x00001001, 0x00000000 } },
21239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
21339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC_OVER clamp modulate dither", scanline_t32cb16blend_clamp_mod_dither, init_y },
21439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000177, { 0x00001002, 0x00000000 } },
21539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
21639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, x888 tx, SRC_OVER clamp modulate dither", scanline_x32cb16blend_clamp_mod_dither, init_y },
21739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000077, { 0x00000001, 0x00000000 } },
21839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
21939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC clamp", scanline_t32cb16_clamp, init_y  },
22039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000077, { 0x00000002, 0x00000000 } },
22139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
22239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, x888 tx, SRC clamp", scanline_t32cb16_clamp, init_y  },
22339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000177, { 0x00000001, 0x00000000 } },
22439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
22539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 8888 tx, SRC clamp dither", scanline_t32cb16_clamp_dither, init_y  },
22639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000177, { 0x00000002, 0x00000000 } },
22739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
22839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, x888 tx, SRC clamp dither", scanline_t32cb16_clamp_dither, init_y  },
22939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03010104, 0x00000077, { 0x00000004, 0x00000000 } },
23039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
23139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 565 tx, SRC clamp", scanline_t16cb16_clamp, init_y  },
23239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    { { { 0x03515104, 0x00000077, { 0x00001004, 0x00000000 } },
23339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0x0000003F } } },
23439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        "565 fb, 565 tx, SRC_OVER clamp", scanline_t16cb16blend_clamp_mod, init_y  },
235f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewell    { { { 0x03515104, 0x00000077, { 0x00000000, 0x00000000 } },
236f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewell        { 0xFFFFFFFF, 0xFFFFFFFF, { 0xFFFFFFFF, 0xFFFFFFFF } } },
237f9e8ab03bd93d98567e96822535090a877594abaMartyn Capewell        "565 fb, 8888 fixed color", scanline_col32cb16blend, init_y_packed  },
238dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x00000000, 0x00000000, { 0x00000000, 0x00000000 } },
239dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x00000000, 0x00000007, { 0x00000000, 0x00000000 } } },
240dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(nop) alpha test", scanline_noop, init_y_noop },
241dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x00000000, 0x00000000, { 0x00000000, 0x00000000 } },
242dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x00000000, 0x00000070, { 0x00000000, 0x00000000 } } },
243dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(nop) depth test", scanline_noop, init_y_noop },
244dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x05000000, 0x00000000, { 0x00000000, 0x00000000 } },
245dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x0F000000, 0x00000080, { 0x00000000, 0x00000000 } } },
246dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(nop) logic_op", scanline_noop, init_y_noop },
247dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0xF0000000, 0x00000000, { 0x00000000, 0x00000000 } },
248dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xF0000000, 0x00000080, { 0x00000000, 0x00000000 } } },
249dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(nop) color mask", scanline_noop, init_y_noop },
250dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x0F000000, 0x00000077, { 0x00000000, 0x00000000 } },
251dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFF000000, 0x000000F7, { 0x00000000, 0x00000000 } } },
252dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(set) logic_op", scanline_set, init_y_noop },
253dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x00000000, 0x00000077, { 0x00000000, 0x00000000 } },
254dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFF000000, 0x000000F7, { 0x00000000, 0x00000000 } } },
255dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(clear) logic_op", scanline_clear, init_y_noop },
256dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x03000000, 0x00000077, { 0x00000000, 0x00000000 } },
257dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFFFFFF00, 0x000000F7, { 0x00000000, 0x00000000 } } },
258dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(clear) blending 0/0", scanline_clear, init_y_noop },
259dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    { { { 0x00000000, 0x00000000, { 0x00000000, 0x00000000 } },
260dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x0000003F, 0x00000000, { 0x00000000, 0x00000000 } } },
261dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        "(error) invalid color-buffer format", scanline_noop, init_y_error },
262dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
263dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic const needs_filter_t noblend1to1 = {
264dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // (disregard dithering, see below)
265dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x03010100, 0x00000077, { 0x00000A00, 0x00000000 } },
266dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFFFFFFC0, 0xFFFFFEFF, { 0xFFFFFFC0, 0x0000003F } }
267dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
268dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic  const needs_filter_t fill16noblend = {
269dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0x03010100, 0x00000077, { 0x00000000, 0x00000000 } },
270dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { 0xFFFFFFC0, 0xFFFFFFFF, { 0x0000003F, 0x0000003F } }
271dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
272dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
273dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
274dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
275dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ANDROID_ARM_CODEGEN
2762bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind
2772bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#if defined(__mips__)
2782bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lindstatic CodeCache gCodeCache(32 * 1024);
2792bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#else
280dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic CodeCache gCodeCache(12 * 1024);
2812bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#endif
282dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
283dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectclass ScanlineAssembly : public Assembly {
284dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    AssemblyKey<needs_t> mKey;
285dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectpublic:
286dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    ScanlineAssembly(needs_t needs, size_t size)
287dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        : Assembly(size), mKey(needs) { }
288dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const AssemblyKey<needs_t>& key() const { return mKey; }
289dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project};
290dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
291dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
292dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
293dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
294dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid ggl_init_scanline(context_t* c)
295dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
296dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->init_y = init_y;
297dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->step_y = step_y__generic;
298dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline = scanline;
299dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
300dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
301dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid ggl_uninit_scanline(context_t* c)
302dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
303dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (c->state.buffers.coverage)
304dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        free(c->state.buffers.coverage);
305dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ANDROID_ARM_CODEGEN
306dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (c->scanline_as)
307dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->scanline_as->decStrong(c);
308dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
309dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
310dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
311dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
312dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
313dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void pick_scanline(context_t* c)
314dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
315dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if (!defined(DEBUG__CODEGEN_ONLY) || (DEBUG__CODEGEN_ONLY == 0))
316dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
317dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ANDROID_CODEGEN == ANDROID_CODEGEN_GENERIC
318dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->init_y = init_y;
319dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->step_y = step_y__generic;
320dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline = scanline;
321dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    return;
322dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
323dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
324dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    //printf("*** needs [%08lx:%08lx:%08lx:%08lx]\n",
325dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    //    c->state.needs.n, c->state.needs.p,
326dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    //    c->state.needs.t[0], c->state.needs.t[1]);
327dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
328dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // first handle the special case that we cannot test with a filter
329dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const uint32_t cb_format = GGL_READ_NEEDS(CB_FORMAT, c->state.needs.n);
330dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (GGL_READ_NEEDS(T_FORMAT, c->state.needs.t[0]) == cb_format) {
331dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (c->state.needs.match(noblend1to1)) {
332dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // this will match regardless of dithering state, since both
333dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // src and dest have the same format anyway, there is no dithering
334dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // to be done.
335dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            const GGLFormat* f =
336dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                &(c->formats[GGL_READ_NEEDS(T_FORMAT, c->state.needs.t[0])]);
337dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            if ((f->components == GGL_RGB) ||
338dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                (f->components == GGL_RGBA) ||
339dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                (f->components == GGL_LUMINANCE) ||
340dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                (f->components == GGL_LUMINANCE_ALPHA))
341dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            {
342dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // format must have all of RGB components
343dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // (so the current color doesn't show through)
344dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                c->scanline = scanline_memcpy;
345dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                c->init_y = init_y_noop;
346dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                return;
347dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
348dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
349dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
350dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
351dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (c->state.needs.match(fill16noblend)) {
352dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->init_y = init_y_packed;
353dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        switch (c->formats[cb_format].size) {
354dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case 1: c->scanline = scanline_memset8;  return;
355dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case 2: c->scanline = scanline_memset16; return;
356dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case 4: c->scanline = scanline_memset32; return;
357dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
358dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
359dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
360dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const int numFilters = sizeof(shortcuts)/sizeof(shortcut_t);
361dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    for (int i=0 ; i<numFilters ; i++) {
362dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (c->state.needs.match(shortcuts[i].filter)) {
363dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->scanline = shortcuts[i].scanline;
364dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->init_y = shortcuts[i].init_y;
365dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            return;
366dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
367dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
368dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
369dccddee972e5fd93409dc874e0a46fd5ae659b16Vladimir Chtchetkine#if DEBUG_NEEDS
3704163b45949c0382f0370bc2a25fcbb6c07c4c5ebSteve Block    ALOGI("Needs: n=0x%08x p=0x%08x t0=0x%08x t1=0x%08x",
37139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner         c->state.needs.n, c->state.needs.p,
37239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner         c->state.needs.t[0], c->state.needs.t[1]);
37339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner#endif
37439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner
375dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif // DEBUG__CODEGEN_ONLY
376dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
377dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->init_y = init_y;
378dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->step_y = step_y__generic;
379dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
380dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ANDROID_ARM_CODEGEN
381dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // we're going to have to generate some code...
382dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // here, generate code for our pixel pipeline
383dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const AssemblyKey<needs_t> key(c->state.needs);
384dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    sp<Assembly> assembly = gCodeCache.lookup(key);
385dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (assembly == 0) {
386dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // create a new assembly region
387dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        sp<ScanlineAssembly> a = new ScanlineAssembly(c->state.needs,
388dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                ASSEMBLY_SCRATCH_SIZE);
389dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // initialize our assembler
3902bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#if defined(__arm__)
391dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        GGLAssembler assembler( new ARMAssembler(a) );
392dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        //GGLAssembler assembler(
393dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        //        new ARMAssemblerOptimizer(new ARMAssembler(a)) );
3942bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#endif
3952bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#if defined(__mips__)
3962bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind        GGLAssembler assembler( new ArmToMipsAssembler(a) );
3972bc2b792782b304b15d8c48b54916a9b3fa3a7acPaul Lind#endif
398dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // generate the scanline code for the given needs
399dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        int err = assembler.scanline(c->state.needs, c);
400dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (ggl_likely(!err)) {
401dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // finally, cache this assembly
402dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            err = gCodeCache.cache(a->key(), a);
403dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
404dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (ggl_unlikely(err)) {
4058aeb6e244a484305428ffbbc4be64d51e9bccdaaSteve Block            ALOGE("error generating or caching assembly. Reverting to NOP.");
406dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->scanline = scanline_noop;
407dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->init_y = init_y_noop;
408dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->step_y = step_y__nop;
409dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            return;
410dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
411dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        assembly = a;
412dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
413dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
414dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // release the previous assembly
415dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (c->scanline_as) {
416dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->scanline_as->decStrong(c);
417dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
418dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
4194163b45949c0382f0370bc2a25fcbb6c07c4c5ebSteve Block    //ALOGI("using generated pixel-pipeline");
420dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline_as = assembly.get();
421dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline_as->incStrong(c); //  hold on to assembly
422dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline = (void(*)(context_t* c))assembly->base();
423dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
4244f07a1f826ddb3669c8da2b2a92983f01df43d54Steve Block//    ALOGW("using generic (slow) pixel-pipeline");
425dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    c->scanline = scanline;
426dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
427dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
428dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
429dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid ggl_pick_scanline(context_t* c)
430dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
431dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    pick_scanline(c);
432dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if ((c->state.enables & GGL_ENABLE_W) &&
433dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        (c->state.enables & GGL_ENABLE_TMUS))
434dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    {
435dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->span = c->scanline;
436dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->scanline = scanline_perspective;
437dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (!(c->state.enabled_tmu & (c->state.enabled_tmu - 1))) {
438dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // only one TMU enabled
439dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->scanline = scanline_perspective_single;
440dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
441dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
442dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
443dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
444dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
445dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
446dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void blending(context_t* c, pixel_t* fragment, pixel_t* fb);
447dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void blend_factor(context_t* c, pixel_t* r, uint32_t factor,
448dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        const pixel_t* src, const pixel_t* dst);
449dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic void rescale(uint32_t& u, uint8_t& su, uint32_t& v, uint8_t& sv);
450dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
451dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if ANDROID_ARM_CODEGEN && (ANDROID_CODEGEN == ANDROID_CODEGEN_GENERATED)
452dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
453dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// no need to compile the generic-pipeline, it can't be reached
454dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid scanline(context_t*)
455dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
456dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
457dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
458dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#else
459dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
460dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid rescale(uint32_t& u, uint8_t& su, uint32_t& v, uint8_t& sv)
461dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
462dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (su && sv) {
463dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (su > sv) {
464dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            v = ggl_expand(v, sv, su);
465dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            sv = su;
466dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        } else if (su < sv) {
467dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            u = ggl_expand(u, su, sv);
468dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            su = sv;
469dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
470dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
471dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
472dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
473dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid blending(context_t* c, pixel_t* fragment, pixel_t* fb)
474dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
475dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    rescale(fragment->c[0], fragment->s[0], fb->c[0], fb->s[0]);
476dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    rescale(fragment->c[1], fragment->s[1], fb->c[1], fb->s[1]);
477dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    rescale(fragment->c[2], fragment->s[2], fb->c[2], fb->s[2]);
478dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    rescale(fragment->c[3], fragment->s[3], fb->c[3], fb->s[3]);
479dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
480dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    pixel_t sf, df;
481dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    blend_factor(c, &sf, c->state.blend.src, fragment, fb);
482dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    blend_factor(c, &df, c->state.blend.dst, fragment, fb);
483dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
484dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    fragment->c[1] =
485dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            gglMulAddx(fragment->c[1], sf.c[1], gglMulx(fb->c[1], df.c[1]));
486dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    fragment->c[2] =
487dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            gglMulAddx(fragment->c[2], sf.c[2], gglMulx(fb->c[2], df.c[2]));
488dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    fragment->c[3] =
489dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            gglMulAddx(fragment->c[3], sf.c[3], gglMulx(fb->c[3], df.c[3]));
490dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
491dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (c->state.blend.alpha_separate) {
492dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        blend_factor(c, &sf, c->state.blend.src_alpha, fragment, fb);
493dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        blend_factor(c, &df, c->state.blend.dst_alpha, fragment, fb);
494dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
495dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
496dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    fragment->c[0] =
497dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            gglMulAddx(fragment->c[0], sf.c[0], gglMulx(fb->c[0], df.c[0]));
498dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
499dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // clamp to 1.0
500dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (fragment->c[0] >= (1LU<<fragment->s[0]))
501dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment->c[0] = (1<<fragment->s[0])-1;
502dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (fragment->c[1] >= (1LU<<fragment->s[1]))
503dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment->c[1] = (1<<fragment->s[1])-1;
504dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (fragment->c[2] >= (1LU<<fragment->s[2]))
505dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment->c[2] = (1<<fragment->s[2])-1;
506dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (fragment->c[3] >= (1LU<<fragment->s[3]))
507dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment->c[3] = (1<<fragment->s[3])-1;
508dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
509dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
510dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic inline int blendfactor(uint32_t x, uint32_t size, uint32_t def = 0)
511dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
512dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (!size)
513dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        return def;
514dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
515dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // scale to 16 bits
516dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (size > 16) {
517dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        x >>= (size - 16);
518dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } else if (size < 16) {
519dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        x = ggl_expand(x, size, 16);
520dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
521dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    x += x >> 15;
522dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    return x;
523dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
524dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
525dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid blend_factor(context_t* c, pixel_t* r,
526dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        uint32_t factor, const pixel_t* src, const pixel_t* dst)
527dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
528dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    switch (factor) {
529dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ZERO:
530dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
531dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
532dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
533dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = 0;
534dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
535dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ONE:
536dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
537dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
538dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
539dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = FIXED_ONE;
540dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
541dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_DST_COLOR:
542dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] = blendfactor(dst->c[1], dst->s[1]);
543dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] = blendfactor(dst->c[2], dst->s[2]);
544dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] = blendfactor(dst->c[3], dst->s[3]);
545dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = blendfactor(dst->c[0], dst->s[0]);
546dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
547dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_SRC_COLOR:
548dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] = blendfactor(src->c[1], src->s[1]);
549dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] = blendfactor(src->c[2], src->s[2]);
550dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] = blendfactor(src->c[3], src->s[3]);
551dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = blendfactor(src->c[0], src->s[0]);
552dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
553dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ONE_MINUS_DST_COLOR:
554dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] = FIXED_ONE - blendfactor(dst->c[1], dst->s[1]);
555dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] = FIXED_ONE - blendfactor(dst->c[2], dst->s[2]);
556dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] = FIXED_ONE - blendfactor(dst->c[3], dst->s[3]);
557dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = FIXED_ONE - blendfactor(dst->c[0], dst->s[0]);
558dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
559dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ONE_MINUS_SRC_COLOR:
560dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] = FIXED_ONE - blendfactor(src->c[1], src->s[1]);
561dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] = FIXED_ONE - blendfactor(src->c[2], src->s[2]);
562dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] = FIXED_ONE - blendfactor(src->c[3], src->s[3]);
563dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = FIXED_ONE - blendfactor(src->c[0], src->s[0]);
564dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
565dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_SRC_ALPHA:
566dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
567dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
568dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
569dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = blendfactor(src->c[0], src->s[0], FIXED_ONE);
570dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
571dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ONE_MINUS_SRC_ALPHA:
572dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
573dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
574dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
575dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = FIXED_ONE - blendfactor(src->c[0], src->s[0], FIXED_ONE);
576dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
577dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_DST_ALPHA:
578dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
579dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
580dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
581dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = blendfactor(dst->c[0], dst->s[0], FIXED_ONE);
582dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
583dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_ONE_MINUS_DST_ALPHA:
584dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[1] =
585dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[2] =
586dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[3] =
587dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r->c[0] = FIXED_ONE - blendfactor(dst->c[0], dst->s[0], FIXED_ONE);
588dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
589dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        case GGL_SRC_ALPHA_SATURATE:
590dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            // XXX: GGL_SRC_ALPHA_SATURATE
591dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            break;
592dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
593dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
594dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
595dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic GGLfixed wrapping(int32_t coord, uint32_t size, int tx_wrap)
596dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
597dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGLfixed d;
598dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (tx_wrap == GGL_REPEAT) {
599dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        d = (uint32_t(coord)>>16) * size;
600dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } else if (tx_wrap == GGL_CLAMP) { // CLAMP_TO_EDGE semantics
601dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        const GGLfixed clamp_min = FIXED_HALF;
602dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        const GGLfixed clamp_max = (size << 16) - FIXED_HALF;
603dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (coord < clamp_min)     coord = clamp_min;
604dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (coord > clamp_max)     coord = clamp_max;
605dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        d = coord;
606dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } else { // 1:1
607dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        const GGLfixed clamp_min = 0;
608dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        const GGLfixed clamp_max = (size << 16);
609dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (coord < clamp_min)     coord = clamp_min;
610dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (coord > clamp_max)     coord = clamp_max;
611dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        d = coord;
612dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
613dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    return d;
614dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
615dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
616dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectstatic inline
617dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source ProjectGGLcolor ADJUST_COLOR_ITERATOR(GGLcolor v, GGLcolor dvdx, int len)
618dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
619dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const int32_t end = dvdx * (len-1) + v;
620dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (end < 0)
621dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        v -= end;
622dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    v &= ~(v>>31);
623dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    return v;
624dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
625dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
626dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectvoid scanline(context_t* c)
627dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project{
628dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const uint32_t enables = c->state.enables;
629dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const int xs = c->iterators.xl;
630dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const int x1 = c->iterators.xr;
631dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	int xc = x1 - xs;
632dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    const int16_t* covPtr = c->state.buffers.coverage + xs;
633dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
634dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // All iterated values are sampled at the pixel center
635dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
636dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // reset iterators for that scanline...
637dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGLcolor r, g, b, a;
638dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    iterators_t& ci = c->iterators;
639dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (enables & GGL_ENABLE_SMOOTH) {
640dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        r = (xs * c->shade.drdx) + ci.ydrdy;
641dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        g = (xs * c->shade.dgdx) + ci.ydgdy;
642dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        b = (xs * c->shade.dbdx) + ci.ydbdy;
643dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        a = (xs * c->shade.dadx) + ci.ydady;
644dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        r = ADJUST_COLOR_ITERATOR(r, c->shade.drdx, xc);
645dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        g = ADJUST_COLOR_ITERATOR(g, c->shade.dgdx, xc);
646dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        b = ADJUST_COLOR_ITERATOR(b, c->shade.dbdx, xc);
647dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        a = ADJUST_COLOR_ITERATOR(a, c->shade.dadx, xc);
648dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } else {
649dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        r = ci.ydrdy;
650dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        g = ci.ydgdy;
651dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        b = ci.ydbdy;
652dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        a = ci.ydady;
653dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
654dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
655dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    // z iterators are 1.31
656dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGLfixed z = (xs * c->shade.dzdx) + ci.ydzdy;
657dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    GGLfixed f = (xs * c->shade.dfdx) + ci.ydfdy;
658dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
659dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    struct {
660dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        GGLfixed s, t;
661dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    } tc[GGL_TEXTURE_UNIT_COUNT];
662dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    if (enables & GGL_ENABLE_TMUS) {
663dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; ++i) {
664dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            if (c->state.texture[i].enable) {
665dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                texture_iterators_t& ti = c->state.texture[i].iterators;
666dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (enables & GGL_ENABLE_W) {
667dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].s = ti.ydsdy;
668dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].t = ti.ydtdy;
669dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                } else {
670dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].s = (xs * ti.dsdx) + ti.ydsdy;
671dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].t = (xs * ti.dtdx) + ti.ydtdy;
672dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
673dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
674dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
675dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    }
676dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
677dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    pixel_t fragment;
678dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    pixel_t texel;
679dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project    pixel_t fb;
680dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
681dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	uint32_t x = xs;
682dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	uint32_t y = c->iterators.y;
683dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
684dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	while (xc--) {
685dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
686dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        { // just a scope
687dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
688dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		// read color (convert to 8 bits by keeping only the integer part)
689dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.s[1] = fragment.s[2] =
690dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.s[3] = fragment.s[0] = 8;
691dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[1] = r >> (GGL_COLOR_BITS-8);
692dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[2] = g >> (GGL_COLOR_BITS-8);
693dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[3] = b >> (GGL_COLOR_BITS-8);
694dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[0] = a >> (GGL_COLOR_BITS-8);
695dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
696dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		// texturing
697dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_TMUS) {
698dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            for (int i=0 ; i<GGL_TEXTURE_UNIT_COUNT ; ++i) {
699dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                texture_t& tx = c->state.texture[i];
700dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (!tx.enable)
701dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    continue;
702dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                texture_iterators_t& ti = tx.iterators;
703dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                int32_t u, v;
704dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
705dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // s-coordinate
706dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (tx.s_coord != GGL_ONE_TO_ONE) {
707dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    const int w = tx.surface.width;
708dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u = wrapping(tc[i].s, w, tx.s_wrap);
709dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].s += ti.dsdx;
710dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                } else {
711dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u = (((tx.shade.is0>>16) + x)<<16) + FIXED_HALF;
712dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
713dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
714dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // t-coordinate
715dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (tx.t_coord != GGL_ONE_TO_ONE) {
716dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    const int h = tx.surface.height;
717dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v = wrapping(tc[i].t, h, tx.t_wrap);
718dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tc[i].t += ti.dtdx;
719dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                } else {
720dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v = (((tx.shade.it0>>16) + y)<<16) + FIXED_HALF;
721dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
722dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
723dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // read texture
724dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (tx.mag_filter == GGL_NEAREST &&
725dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.min_filter == GGL_NEAREST)
726dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                {
727dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u >>= 16;
728dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v >>= 16;
729dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.surface.read(&tx.surface, c, u, v, &texel);
730dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                } else {
731dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    const int w = tx.surface.width;
732dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    const int h = tx.surface.height;
733dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u -= FIXED_HALF;
734dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v -= FIXED_HALF;
735dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    int u0 = u >> 16;
736dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    int v0 = v >> 16;
737dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    int u1 = u0 + 1;
738dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    int v1 = v0 + 1;
739dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    if (tx.s_wrap == GGL_REPEAT) {
740dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u0<0)  u0 += w;
741dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u1<0)  u1 += w;
742dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u0>=w) u0 -= w;
743dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u1>=w) u1 -= w;
744dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    } else {
745dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u0<0)  u0 = 0;
746dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u1<0)  u1 = 0;
747dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u0>=w) u0 = w-1;
748dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (u1>=w) u1 = w-1;
749dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    }
750dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    if (tx.t_wrap == GGL_REPEAT) {
751dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v0<0)  v0 += h;
752dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v1<0)  v1 += h;
753dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v0>=h) v0 -= h;
754dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v1>=h) v1 -= h;
755dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    } else {
756dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v0<0)  v0 = 0;
757dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v1<0)  v1 = 0;
758dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v0>=h) v0 = h-1;
759dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (v1>=h) v1 = h-1;
760dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    }
761dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    pixel_t texels[4];
762dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint32_t mm[4];
763dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.surface.read(&tx.surface, c, u0, v0, &texels[0]);
764dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.surface.read(&tx.surface, c, u0, v1, &texels[1]);
765dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.surface.read(&tx.surface, c, u1, v0, &texels[2]);
766dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    tx.surface.read(&tx.surface, c, u1, v1, &texels[3]);
767dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u = (u >> 12) & 0xF;
768dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v = (v >> 12) & 0xF;
769dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    u += u>>3;
770dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    v += v>>3;
771dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    mm[0] = (0x10 - u) * (0x10 - v);
772dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    mm[1] = (0x10 - u) * v;
773dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    mm[2] = u * (0x10 - v);
774dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    mm[3] = 0x100 - (mm[0] + mm[1] + mm[2]);
775dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    for (int j=0 ; j<4 ; j++) {
776dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        texel.s[j] = texels[0].s[j];
777dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (!texel.s[j]) continue;
778dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        texel.s[j] += 8;
779dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        texel.c[j] =    texels[0].c[j]*mm[0] +
780dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        texels[1].c[j]*mm[1] +
781dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        texels[2].c[j]*mm[2] +
782dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                                        texels[3].c[j]*mm[3] ;
783dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    }
784dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
785dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
786dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // Texture environnement...
787dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                for (int j=0 ; j<4 ; j++) {
788dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint32_t& Cf = fragment.c[j];
789dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint32_t& Ct = texel.c[j];
790dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint8_t& sf  = fragment.s[j];
791dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint8_t& st  = texel.s[j];
792dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint32_t At = texel.c[0];
793dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    uint8_t sat = texel.s[0];
794dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    switch (tx.env) {
795dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    case GGL_REPLACE:
796dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (st) {
797dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            Cf = Ct;
798dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            sf = st;
799dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
800dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        break;
801dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    case GGL_MODULATE:
802dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (st) {
803dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            uint32_t factor = Ct + (Ct>>(st-1));
804dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            Cf = (Cf * factor) >> st;
805dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
806dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        break;
807dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    case GGL_DECAL:
808dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (sat) {
809dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            rescale(Cf, sf, Ct, st);
810dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            Cf += ((Ct - Cf) * (At + (At>>(sat-1)))) >> sat;
811dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
812dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        break;
813dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    case GGL_BLEND:
814dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (st) {
815dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            uint32_t Cc = tx.env_color[i];
816dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            if (sf>8)       Cc = (Cc * ((1<<sf)-1))>>8;
817dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            else if (sf<8)  Cc = (Cc - (Cc>>(8-sf)))>>(8-sf);
818dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            uint32_t factor = Ct + (Ct>>(st-1));
819dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            Cf = ((((1<<st) - factor) * Cf) + Ct*Cc)>>st;
820dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
821dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        break;
822dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    case GGL_ADD:
823dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        if (st) {
824dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            rescale(Cf, sf, Ct, st);
825dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                            Cf += Ct;
826dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        }
827dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                        break;
828dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    }
829dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
830dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
831dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		}
832dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
833dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // coverage application
834dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_AA) {
835dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            int16_t cf = *covPtr++;
836dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            fragment.c[0] = (int64_t(fragment.c[0]) * cf) >> 15;
837dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
838dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
839dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // alpha-test
840dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_ALPHA_TEST) {
841dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            GGLcolor ref = c->state.alpha_test.ref;
842dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            GGLcolor alpha = (uint64_t(fragment.c[0]) *
843dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    ((1<<GGL_COLOR_BITS)-1)) / ((1<<fragment.s[0])-1);
844dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            switch (c->state.alpha_test.func) {
845dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_NEVER:     goto discard;
846dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_LESS:      if (alpha<ref)  break; goto discard;
847dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_EQUAL:     if (alpha==ref) break; goto discard;
848dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_LEQUAL:    if (alpha<=ref) break; goto discard;
849dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_GREATER:   if (alpha>ref)  break; goto discard;
850dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_NOTEQUAL:  if (alpha!=ref) break; goto discard;
851dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            case GGL_GEQUAL:    if (alpha>=ref) break; goto discard;
852dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
853dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
854dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
855dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // depth test
856dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (c->state.buffers.depth.format) {
857dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            if (enables & GGL_ENABLE_DEPTH_TEST) {
858dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                surface_t* cb = &(c->state.buffers.depth);
859dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                uint16_t* p = (uint16_t*)(cb->data)+(x+(cb->stride*y));
860dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                uint16_t zz = uint32_t(z)>>(16);
861dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                uint16_t depth = *p;
862dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                switch (c->state.depth_test.func) {
863dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_NEVER:     goto discard;
864dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_LESS:      if (zz<depth)    break; goto discard;
865dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_EQUAL:     if (zz==depth)   break; goto discard;
866dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_LEQUAL:    if (zz<=depth)   break; goto discard;
867dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_GREATER:   if (zz>depth)    break; goto discard;
868dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_NOTEQUAL:  if (zz!=depth)   break; goto discard;
869dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                case GGL_GEQUAL:    if (zz>=depth)   break; goto discard;
870dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
871dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                // depth buffer is not enabled, if depth-test is not enabled
872dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project/*
873dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.s[1] = fragment.s[2] =
874dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.s[3] = fragment.s[0] = 8;
875dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[1] =
876dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[2] =
877dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[3] =
878dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        fragment.c[0] = 255 - (zz>>8);
879dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project*/
880dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                if (c->state.mask.depth) {
881dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    *p = zz;
882dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                }
883dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
884dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
885dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
886dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // fog
887dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_FOG) {
888dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            for (int i=1 ; i<=3 ; i++) {
889dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                GGLfixed fc = (c->state.fog.color[i] * 0x10000) / 0xFF;
890dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                uint32_t& c = fragment.c[i];
891dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                uint8_t& s  = fragment.s[i];
892dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                c = (c * 0x10000) / ((1<<s)-1);
893dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                c = gglMulAddx(c, f, gglMulx(fc, 0x10000 - f));
894dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                s = 16;
895dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            }
896dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
897dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
898dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        // blending
899dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_BLENDING) {
900dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            fb.c[1] = fb.c[2] = fb.c[3] = fb.c[0] = 0; // placate valgrind
901dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            fb.s[1] = fb.s[2] = fb.s[3] = fb.s[0] = 0;
902dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            c->state.buffers.color.read(
903dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                    &(c->state.buffers.color), c, x, y, &fb);
904dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            blending( c, &fragment, &fb );
905dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
906dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
907dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		// write
908dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        c->state.buffers.color.write(
909dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project                &(c->state.buffers.color), c, x, y, &fragment);
910dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
911dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
912dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Projectdiscard:
913dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project		// iterate...
914dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        x += 1;
915dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        if (enables & GGL_ENABLE_SMOOTH) {
916dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            r += c->shade.drdx;
917dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            g += c->shade.dgdx;
918dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            b += c->shade.dbdx;
919dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project            a += c->shade.dadx;
920dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        }
921dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        z += c->shade.dzdx;
922dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project        f += c->shade.dfdx;
923dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project	}
924dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project}
925dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
926dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif // ANDROID_ARM_CODEGEN && (ANDROID_CODEGEN == ANDROID_CODEGEN_GENERATED)
927dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
928dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project// ----------------------------------------------------------------------------
929dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#if 0
930dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#pragma mark -
931dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#pragma mark Scanline
932dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project#endif
933dd7bc3319deb2b77c5d07a51b7d6cd7e11b5beb0The Android Open Source Project
93439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner/* Used to parse a 32-bit source texture linearly. Usage is:
93539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
93639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * horz_iterator32  hi(context);
93739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * while (...) {
93839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *    uint32_t  src_pixel = hi.get_pixel32();
93939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *    ...
94039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * }
94139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner *
94239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner * Use only for one-to-one texture mapping.
94339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner */
94439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turnerstruct horz_iterator32 {
94539764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    horz_iterator32(context_t* c) {
94639764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        const int x = c->iterators.xl;
94739764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        const int y = c->iterators.y;
94839764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        texture_t& tx = c->state.texture[0];
94939764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        const int32_t u = (tx.shade.is0>>16) + x;
95039764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        const int32_t v = (tx.shade.it0>>16) + y;
95139764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        m_src = reinterpret_cast<uint32_t*>(tx.surface.data)+(u+(tx.surface.stride*v));
95239764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    }
95339764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner    uint32_t  get_pixel32() {
95439764f41a5a6bff89160d644f509a05061365041David 'Digit' Turner        return *m_src++;
955