gltrace_fixup.cpp revision 3f194e6e3a62cbb846e8948eac8e4ce9aa7444a6
10469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy/* 20469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Copyright 2011, The Android Open Source Project 30469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * 40469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Licensed under the Apache License, Version 2.0 (the "License"); 50469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * you may not use this file except in compliance with the License. 60469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * You may obtain a copy of the License at 70469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * 80469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * http://www.apache.org/licenses/LICENSE-2.0 90469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * 100469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * Unless required by applicable law or agreed to in writing, software 110469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * distributed under the License is distributed on an "AS IS" BASIS, 120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * See the License for the specific language governing permissions and 140469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy * limitations under the License. 150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy */ 160469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 170469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include <cutils/log.h> 180469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include <GLES2/gl2.h> 190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace.pb.h" 210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_context.h" 220469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy#include "gltrace_fixup.h" 230469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 240469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamynamespace android { 250469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamynamespace gltrace { 260469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 270469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyunsigned getBytesPerTexel(const GLenum format, const GLenum type) { 280469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* 290469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy Description from glTexImage2D spec: 300469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 310469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy Data is read from data as a sequence of unsigned bytes or shorts, depending on type. 320469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy When type is GL_UNSIGNED_BYTE, each of the bytes is interpreted as one color component. 330469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy When type is one of GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT_4_4_4_4, or 340469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GL_UNSIGNED_SHORT_5_5_5_1, each unsigned short value is interpreted as containing all 350469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy the components for a single texel, with the color components arranged according to 360469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy format. Color components are treated as groups of one, two, three, or four values, 370469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy again based on format. Groups of components are referred to as texels. 380469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 390469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy width × height texels are read from memory, starting at location data. By default, 400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy these texels are taken from adjacent memory locations, except that after all width 410469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy texels are read, the read pointer is advanced to the next four-byte boundary. 420469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy The four-byte row alignment is specified by glPixelStorei with argument 430469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GL_UNPACK_ALIGNMENT, and it can be set to one, two, four, or eight bytes. 440469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy */ 450469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 460469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy switch (type) { 470469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_UNSIGNED_SHORT_5_6_5: 480469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_UNSIGNED_SHORT_4_4_4_4: 490469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_UNSIGNED_SHORT_5_5_5_1: 500469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 2; 510469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_UNSIGNED_BYTE: 520469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 530469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy default: 540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy LOGE("GetBytesPerPixel: unknown type %x", type); 550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy switch (format) { 580469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_ALPHA: 590469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_LUMINANCE: 600469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 1; 610469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_LUMINANCE_ALPHA: 620469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 2; 630469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_RGB: 640469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 3; 650469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GL_RGBA: 660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case 0x80E1: // GL_BGRA_EXT 670469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 4; 680469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy default: 690469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy LOGE("GetBytesPerPixel: unknown format %x", format); 700469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 710469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 720469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy return 1; // in doubt... 730469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 740469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 750469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy/** Generic helper function: extract pointer at argIndex and 760469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy replace it with the C style string at *pointer */ 770469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_CStringPtr(int argIndex, GLMessage *glmsg) { 780469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg = glmsg->mutable_args(argIndex); 790469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLchar *ptr = (GLchar *)arg->intvalue(0); 800469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 810469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg->set_type(GLMessage::DataType::CHAR); 820469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg->set_isarray(true); 830469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg->add_charvalue(ptr); 840469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 850469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 860469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glGetString(GLMessage *glmsg) { 870469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* const GLubyte* GLTrace_glGetString(GLenum name) */ 880469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *ret = glmsg->mutable_returnvalue(); 890469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLchar *ptr = (GLchar *)ret->intvalue(0); 900469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 910469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (ptr != NULL) { 920469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy ret->set_type(GLMessage::DataType::CHAR); 930469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy ret->set_isarray(true); 940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy ret->add_charvalue(ptr); 950469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 960469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 970469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 98a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy/* Add the contents of the framebuffer to the protobuf message */ 9993a826f78f6313db791e6fc880439189897651b3Siva Velusamyvoid fixup_addFBContents(GLTraceContext *context, GLMessage *glmsg, FBBinding fbToRead) { 100a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy void *fbcontents; 1010469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy unsigned fbsize, fbwidth, fbheight; 10293a826f78f6313db791e6fc880439189897651b3Siva Velusamy context->getCompressedFB(&fbcontents, &fbsize, &fbwidth, &fbheight, fbToRead); 1030469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 104a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy GLMessage_FrameBuffer *fb = glmsg->mutable_fb(); 105a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy fb->set_width(fbwidth); 106a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy fb->set_height(fbheight); 107a8cfde8897c840ce6a491a054ade806b41df2a70Siva Velusamy fb->add_contents(fbcontents, fbsize); 1080469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 1090469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1100469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glTexImage2D(GLMessage *glmsg) { 1110469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glTexImage2D(GLenum target, 1120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLint level, 1130469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLint internalformat, 1140469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei width, 1150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei height, 1160469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLint border, 1170469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLenum format, 1180469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLenum type, 1190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLvoid *data); 1200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy */ 1210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_width = glmsg->args(3); 1220469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_height = glmsg->args(4); 1230469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_format = glmsg->args(6); 1240469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_type = glmsg->args(7); 1250469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_data = glmsg->mutable_args(8); 1260469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1270469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei width = arg_width.intvalue(0); 1280469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei height = arg_height.intvalue(0); 1290469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLenum format = arg_format.intvalue(0); 1300469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLenum type = arg_type.intvalue(0); 1310469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy void *data = (void *)arg_data->intvalue(0); 1320469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1330469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy int bytesPerTexel = getBytesPerTexel(format, type); 1340469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1350469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_data->set_type(GLMessage::DataType::BYTE); 1360469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_data->set_isarray(true); 1370469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_data->clear_rawbytes(); 1380469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1390469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (data != NULL) { 1400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_data->add_rawbytes(data, bytesPerTexel * width * height); 1410469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } else { 1420469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy LOGE("fixup_glTexImage2D: image data is NULL.\n"); 1430469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_data->set_type(GLMessage::DataType::VOID); 1440469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy // FIXME: 1450469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy // This will create the texture, but it will be uninitialized. 1460469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy // It can later be initialized with glTexSubImage2D or by 1470469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy // attaching an FBO to it and rendering into the FBO. 1480469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 1490469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 1500469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1510469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glShaderSource(GLMessage *glmsg) { 1520469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glShaderSource(GLuint shader, GLsizei count, const GLchar** string, 1530469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLint* length) */ 1540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_count = glmsg->args(1); 1550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_lenp = glmsg->args(3); 1560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_strpp = glmsg->mutable_args(2); 1570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1580469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei count = arg_count.intvalue(0); 1590469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLchar **stringpp = (GLchar **)arg_strpp->intvalue(0); 1600469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLint *lengthp = (GLint *)arg_lenp.intvalue(0); 1610469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1620469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_strpp->set_type(GLMessage::DataType::CHAR); 1630469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_strpp->set_isarray(true); 1640469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_strpp->clear_charvalue(); 1650469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy ::std::string src = ""; 1670469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy for (int i = 0; i < count; i++) { 1680469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy if (lengthp != NULL) 1690469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy src.append(*stringpp, *lengthp); 1700469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy else 1710469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy src.append(*stringpp); // assume null terminated 1720469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy stringpp++; 1730469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy lengthp++; 1740469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 1750469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1760469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_strpp->add_charvalue(src); 1770469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 1780469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1790469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glUniformGeneric(int argIndex, int nFloats, GLMessage *glmsg) { 1800469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_values = glmsg->mutable_args(argIndex); 1810469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLfloat *src = (GLfloat*)arg_values->intvalue(0); 1820469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1830469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_values->set_type(GLMessage::DataType::FLOAT); 1840469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_values->set_isarray(true); 1850469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_values->clear_floatvalue(); 1860469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1870469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy for (int i = 0; i < nFloats; i++) { 1880469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_values->add_floatvalue(*src++); 1890469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 1900469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 1910469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 1920469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glUniformMatrixGeneric(int matrixSize, GLMessage *glmsg) { 1930469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glUniformMatrix?fv(GLint location, GLsizei count, GLboolean transpose, 1940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLfloat* value) */ 1950469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_count = glmsg->args(1); 1960469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy int n_matrices = arg_count.intvalue(0); 1970469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glUniformGeneric(3, matrixSize * matrixSize * n_matrices, glmsg); 1980469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 1990469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2000469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_GenericIntArray(int argIndex, int nInts, GLMessage *glmsg) { 2010469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_intarray = glmsg->mutable_args(argIndex); 2020469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLint *intp = (GLint *)arg_intarray->intvalue(0); 2030469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2040469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_intarray->set_type(GLMessage::DataType::INT); 2050469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_intarray->set_isarray(true); 2060469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_intarray->clear_intvalue(); 2070469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2080469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy for (int i = 0; i < nInts; i++, intp++) { 2090469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_intarray->add_intvalue(*intp); 2100469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 2110469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 2120469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2130469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glGenGeneric(GLMessage *glmsg) { 2140469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGen*(GLsizei n, GLuint * buffers); */ 2150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType arg_n = glmsg->args(0); 2160469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLsizei n = arg_n.intvalue(0); 2170469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2180469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_GenericIntArray(1, n, glmsg); 2190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 2200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glGetBooleanv(GLMessage *glmsg) { 2220469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGetBooleanv(GLenum pname, GLboolean *params); */ 2230469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_params = glmsg->mutable_args(1); 2240469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLboolean *src = (GLboolean*)arg_params->intvalue(0); 2250469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2260469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->set_type(GLMessage::DataType::BOOL); 2270469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->set_isarray(true); 2280469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->clear_boolvalue(); 2290469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->add_boolvalue(*src); 2300469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 2310469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2320469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamyvoid fixup_glGetFloatv(GLMessage *glmsg) { 2330469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGetFloatv(GLenum pname, GLfloat *params); */ 2340469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLMessage_DataType *arg_params = glmsg->mutable_args(1); 2350469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy GLfloat *src = (GLfloat*)arg_params->intvalue(0); 2360469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 2370469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->set_type(GLMessage::DataType::FLOAT); 2380469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->set_isarray(true); 2390469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->clear_floatvalue(); 2400469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy arg_params->add_floatvalue(*src); 2410469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 2420469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 24356ac6ff9bdc3c117e820c5a361ab45049c8b03f8Siva Velusamyvoid fixupGLMessage(GLTraceContext *context, nsecs_t start, nsecs_t end, GLMessage *glmsg) { 24493a826f78f6313db791e6fc880439189897651b3Siva Velusamy // for all messages, set the current context id 24593a826f78f6313db791e6fc880439189897651b3Siva Velusamy glmsg->set_context_id(context->getId()); 24693a826f78f6313db791e6fc880439189897651b3Siva Velusamy 24756ac6ff9bdc3c117e820c5a361ab45049c8b03f8Siva Velusamy // set start time and duration 24856ac6ff9bdc3c117e820c5a361ab45049c8b03f8Siva Velusamy glmsg->set_start_time(start); 24956ac6ff9bdc3c117e820c5a361ab45049c8b03f8Siva Velusamy glmsg->set_duration((unsigned)(end - start)); 25056ac6ff9bdc3c117e820c5a361ab45049c8b03f8Siva Velusamy 25193a826f78f6313db791e6fc880439189897651b3Siva Velusamy // do any custom message dependent processing 2520469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy switch (glmsg->function()) { 2530469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGenBuffers: /* void glGenBuffers(GLsizei n, GLuint * buffers); */ 2540469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGenFramebuffers: /* void glGenFramebuffers(GLsizei n, GLuint * buffers); */ 2550469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGenRenderbuffers: /* void glGenFramebuffers(GLsizei n, GLuint * buffers); */ 2560469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGenTextures: /* void glGenTextures(GLsizei n, GLuint * buffers); */ 2570469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glGenGeneric(glmsg); 2580469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2590469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetAttribLocation: 2600469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetUniformLocation: 2610469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* int glGetAttribLocation(GLuint program, const GLchar* name) */ 2620469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* int glGetUniformLocation(GLuint program, const GLchar* name) */ 2630469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_CStringPtr(1, glmsg); 2640469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2650469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetBooleanv: 2660469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glGetBooleanv(glmsg); 2670469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2680469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetFloatv: 2690469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glGetFloatv(glmsg); 2700469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2710469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetIntegerv: /* void glGetIntegerv(GLenum pname, GLint *params); */ 2720469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_GenericIntArray(1, 1, glmsg); 2730469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2740469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetProgramiv: 2750469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetRenderbufferParameteriv: 2760469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetShaderiv: 2770469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGetProgramiv(GLuint program, GLenum pname, GLint* params) */ 2780469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGetRenderbufferParameteriv(GLenum target, GLenum pname, GLint* params) */ 2790469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glGetShaderiv(GLuint shader, GLenum pname, GLint* params) */ 2800469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_GenericIntArray(2, 1, glmsg); 2810469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2820469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glGetString: 2830469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glGetString(glmsg); 2840469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2850469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glTexImage2D: 2863f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy if (context->getGlobalTraceState()->shouldCollectTextureDataOnGlTexImage()) { 2873f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy fixup_glTexImage2D(glmsg); 2883f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy } 2890469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2900469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glShaderSource: 2910469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glShaderSource(glmsg); 2920469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2930469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glUniformMatrix2fv: 2940469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, 2950469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLfloat* value) */ 2960469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glUniformMatrixGeneric(2, glmsg); 2970469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 2980469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glUniformMatrix3fv: 2990469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glUniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, 3000469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLfloat* value) */ 3010469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glUniformMatrixGeneric(3, glmsg); 3020469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 3030469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glUniformMatrix4fv: 3040469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, 3050469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy const GLfloat* value) */ 3060469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy fixup_glUniformMatrixGeneric(4, glmsg); 3070469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 3080469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy case GLMessage::glDrawArrays: 3090469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glDrawArrays(GLenum mode, GLint first, GLsizei count) */ 3103f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy if (context->getGlobalTraceState()->shouldCollectFbOnGlDraw()) { 3113f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy fixup_addFBContents(context, glmsg, CURRENTLY_BOUND_FB); 3123f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy } 3133f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy break; 3143f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy case GLMessage::glDrawElements: 3150469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy /* void glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) */ 3163f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy if (context->getGlobalTraceState()->shouldCollectFbOnGlDraw()) { 3173f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy fixup_addFBContents(context, glmsg, CURRENTLY_BOUND_FB); 3183f194e6e3a62cbb846e8948eac8e4ce9aa7444a6Siva Velusamy } 3190469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 3200469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy default: 3210469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy break; 3220469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy } 3230469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy} 3240469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy 3250469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}; 3260469dd6d55fa331bfd7de9431da98b6340d82271Siva Velusamy}; 327