David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 2011, The Android Open Source Project |
| 3 | ** |
| 4 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ** you may not use this file except in compliance with the License. |
| 6 | ** You may obtain a copy of the License at |
| 7 | ** |
| 8 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ** |
| 10 | ** Unless required by applicable law or agreed to in writing, software |
| 11 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ** See the License for the specific language governing permissions and |
| 14 | ** limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "header.h" |
| 18 | |
| 19 | namespace android |
| 20 | { |
| 21 | bool capture; // capture after each glDraw* |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 22 | } |
| 23 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 24 | void Debug_glDrawArrays(GLenum mode, GLint first, GLsizei count) |
| 25 | { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 26 | DbgContext * const dbg = getDbgContextThreadSpecific(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 27 | glesv2debugger::Message msg, cmd; |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 28 | msg.set_context_id(reinterpret_cast<int>(dbg)); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 29 | msg.set_type(glesv2debugger::Message_Type_BeforeCall); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 30 | bool expectResponse = dbg->expectResponse.Bit(glesv2debugger::Message_Function_glDrawArrays); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 31 | msg.set_expect_response(expectResponse); |
| 32 | msg.set_function(glesv2debugger::Message_Function_glDrawArrays); |
| 33 | msg.set_arg0(mode); |
| 34 | msg.set_arg1(first); |
| 35 | msg.set_arg2(count); |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 36 | |
| 37 | msg.set_arg7(dbg->maxAttrib); // indicate capturing vertex data |
| 38 | if (dbg->hasNonVBOAttribs) { |
| 39 | std::string * const data = msg.mutable_data(); |
| 40 | for (unsigned i = 0; i < count; i++) |
| 41 | dbg->Fetch(i + first, data); |
| 42 | } |
| 43 | |
| 44 | void * pixels = NULL; |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 45 | int viewport[4] = {}; |
David Li | e9f619f | 2011-04-14 11:20:22 -0700 | [diff] [blame] | 46 | cmd.set_function(glesv2debugger::Message_Function_CONTINUE); |
| 47 | cmd.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 48 | glesv2debugger::Message_Function oldCmd = cmd.function(); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 49 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 50 | expectResponse = cmd.expect_response(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 51 | while (true) { |
| 52 | msg.Clear(); |
| 53 | nsecs_t c0 = systemTime(timeMode); |
| 54 | switch (cmd.function()) { |
| 55 | case glesv2debugger::Message_Function_CONTINUE: |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 56 | dbg->hooks->gl.glDrawArrays(mode, first, count); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 57 | msg.set_time((systemTime(timeMode) - c0) * 1e-6f); |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 58 | msg.set_context_id(reinterpret_cast<int>(dbg)); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 59 | msg.set_function(glesv2debugger::Message_Function_glDrawArrays); |
| 60 | msg.set_type(glesv2debugger::Message_Type_AfterCall); |
| 61 | msg.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 62 | if (!expectResponse) { |
| 63 | cmd.set_function(glesv2debugger::Message_Function_SKIP); |
| 64 | cmd.set_expect_response(false); |
| 65 | } |
| 66 | oldCmd = cmd.function(); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 67 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 68 | expectResponse = cmd.expect_response(); |
| 69 | // TODO: pack glReadPixels data with vertex data instead of |
| 70 | // relying on sperate call for transport, this would allow |
| 71 | // auto generated message loop using EXTEND_Debug macro |
David Li | e7180e8 | 2011-04-08 18:45:45 -0700 | [diff] [blame] | 72 | if (dbg->captureDraw > 0) { |
| 73 | dbg->captureDraw--; |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 74 | dbg->hooks->gl.glGetIntegerv(GL_VIEWPORT, viewport); |
David Li | 6a5ca48 | 2011-03-21 10:02:30 -0700 | [diff] [blame] | 75 | // LOGD("glDrawArrays CAPTURE: x=%d y=%d width=%d height=%d format=0x%.4X type=0x%.4X", |
| 76 | // viewport[0], viewport[1], viewport[2], viewport[3], readFormat, readType); |
David Li | f9bc124 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 77 | pixels = dbg->GetReadPixelsBuffer(viewport[2] * viewport[3] * |
David Li | e7180e8 | 2011-04-08 18:45:45 -0700 | [diff] [blame] | 78 | dbg->readBytesPerPixel); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 79 | Debug_glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 80 | GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 81 | } |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 82 | break; |
| 83 | case glesv2debugger::Message_Function_SKIP: |
| 84 | return; |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 85 | case glesv2debugger::Message_Function_SETPROP: |
David Li | fbfc703 | 2011-03-21 16:25:58 -0700 | [diff] [blame] | 86 | SetProp(dbg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 87 | expectResponse = cmd.expect_response(); |
| 88 | if (!expectResponse) // SETPROP is "out of band" |
| 89 | cmd.set_function(oldCmd); |
| 90 | else |
| 91 | Receive(cmd); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 92 | break; |
| 93 | default: |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 94 | GenerateCall(dbg, cmd, msg, NULL); |
| 95 | msg.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 96 | if (!expectResponse) { |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 97 | cmd.set_function(cmd.SKIP); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 98 | cmd.set_expect_response(expectResponse); |
| 99 | } |
| 100 | oldCmd = cmd.function(); |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 101 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 102 | expectResponse = cmd.expect_response(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 103 | break; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 108 | template<typename T> |
| 109 | static inline void FetchIndexed(const unsigned count, const T * indices, |
| 110 | std::string * const data, const DbgContext * const ctx) |
| 111 | { |
| 112 | for (unsigned i = 0; i < count; i++) { |
| 113 | if (!ctx->indexBuffer) |
| 114 | data->append((const char *)(indices + i), sizeof(*indices)); |
| 115 | if (ctx->hasNonVBOAttribs) |
| 116 | ctx->Fetch(indices[i], data); |
| 117 | } |
| 118 | } |
| 119 | |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 120 | void Debug_glDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid* indices) |
| 121 | { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 122 | DbgContext * const dbg = getDbgContextThreadSpecific(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 123 | glesv2debugger::Message msg, cmd; |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 124 | msg.set_context_id(reinterpret_cast<int>(dbg)); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 125 | msg.set_type(glesv2debugger::Message_Type_BeforeCall); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 126 | bool expectResponse = dbg->expectResponse.Bit(glesv2debugger::Message_Function_glDrawElements); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 127 | msg.set_expect_response(expectResponse); |
| 128 | msg.set_function(glesv2debugger::Message_Function_glDrawElements); |
| 129 | msg.set_arg0(mode); |
| 130 | msg.set_arg1(count); |
| 131 | msg.set_arg2(type); |
| 132 | msg.set_arg3(reinterpret_cast<int>(indices)); |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 133 | |
| 134 | msg.set_arg7(dbg->maxAttrib); // indicate capturing vertex data |
| 135 | std::string * const data = msg.mutable_data(); |
| 136 | if (GL_UNSIGNED_BYTE == type) { |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 137 | if (dbg->indexBuffer) { |
David Li | f9bc124 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 138 | FetchIndexed(count, (unsigned char *)dbg->indexBuffer->data + |
| 139 | (unsigned long)indices, data, dbg); |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 140 | } else { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 141 | FetchIndexed(count, (unsigned char *)indices, data, dbg); |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 142 | } |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 143 | } else if (GL_UNSIGNED_SHORT == type) { |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 144 | if (dbg->indexBuffer) { |
David Li | f9bc124 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 145 | FetchIndexed(count, (unsigned short *)((char *)dbg->indexBuffer->data + |
| 146 | (unsigned long)indices), data, dbg); |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 147 | } else { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 148 | FetchIndexed(count, (unsigned short *)indices, data, dbg); |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 149 | } |
| 150 | } else { |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 151 | assert(0); |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 152 | } |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 153 | |
| 154 | void * pixels = NULL; |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 155 | int viewport[4] = {}; |
David Li | e9f619f | 2011-04-14 11:20:22 -0700 | [diff] [blame] | 156 | cmd.set_function(glesv2debugger::Message_Function_CONTINUE); |
| 157 | cmd.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 158 | glesv2debugger::Message_Function oldCmd = cmd.function(); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 159 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 160 | expectResponse = cmd.expect_response(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 161 | while (true) { |
| 162 | msg.Clear(); |
| 163 | nsecs_t c0 = systemTime(timeMode); |
| 164 | switch (cmd.function()) { |
| 165 | case glesv2debugger::Message_Function_CONTINUE: |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 166 | dbg->hooks->gl.glDrawElements(mode, count, type, indices); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 167 | msg.set_time((systemTime(timeMode) - c0) * 1e-6f); |
David Li | 5c425f2 | 2011-03-10 16:40:37 -0800 | [diff] [blame] | 168 | msg.set_context_id(reinterpret_cast<int>(dbg)); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 169 | msg.set_function(glesv2debugger::Message_Function_glDrawElements); |
| 170 | msg.set_type(glesv2debugger::Message_Type_AfterCall); |
| 171 | msg.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 172 | if (!expectResponse) { |
| 173 | cmd.set_function(glesv2debugger::Message_Function_SKIP); |
| 174 | cmd.set_expect_response(false); |
| 175 | } |
| 176 | oldCmd = cmd.function(); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 177 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 178 | expectResponse = cmd.expect_response(); |
| 179 | // TODO: pack glReadPixels data with vertex data instead of |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 180 | // relying on separate call for transport, this would allow |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 181 | // auto generated message loop using EXTEND_Debug macro |
David Li | e7180e8 | 2011-04-08 18:45:45 -0700 | [diff] [blame] | 182 | if (dbg->captureDraw > 0) { |
| 183 | dbg->captureDraw--; |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 184 | dbg->hooks->gl.glGetIntegerv(GL_VIEWPORT, viewport); |
David Li | f9bc124 | 2011-03-22 18:42:03 -0700 | [diff] [blame] | 185 | pixels = dbg->GetReadPixelsBuffer(viewport[2] * viewport[3] * |
David Li | e7180e8 | 2011-04-08 18:45:45 -0700 | [diff] [blame] | 186 | dbg->readBytesPerPixel); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 187 | Debug_glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], |
Mathias Agopian | 575e01c6 | 2011-09-13 18:15:50 -0700 | [diff] [blame] | 188 | GL_RGBA, GL_UNSIGNED_BYTE, pixels); |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 189 | } |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 190 | break; |
| 191 | case glesv2debugger::Message_Function_SKIP: |
| 192 | return; |
David Li | 940c3f8 | 2011-03-10 19:07:42 -0800 | [diff] [blame] | 193 | case glesv2debugger::Message_Function_SETPROP: |
David Li | fbfc703 | 2011-03-21 16:25:58 -0700 | [diff] [blame] | 194 | SetProp(dbg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 195 | expectResponse = cmd.expect_response(); |
| 196 | if (!expectResponse) // SETPROP is "out of band" |
| 197 | cmd.set_function(oldCmd); |
| 198 | else |
| 199 | Receive(cmd); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 200 | break; |
| 201 | default: |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 202 | GenerateCall(dbg, cmd, msg, NULL); |
| 203 | msg.set_expect_response(expectResponse); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 204 | if (!expectResponse) { |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 205 | cmd.set_function(cmd.SKIP); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 206 | cmd.set_expect_response(expectResponse); |
| 207 | } |
| 208 | oldCmd = cmd.function(); |
David Li | 291f5fe | 2011-03-21 17:42:50 -0700 | [diff] [blame] | 209 | Send(msg, cmd); |
David Li | e2ad4d0 | 2011-04-08 18:41:00 -0700 | [diff] [blame] | 210 | expectResponse = cmd.expect_response(); |
David Li | 55c94cc | 2011-03-04 17:50:48 -0800 | [diff] [blame] | 211 | break; |
| 212 | } |
| 213 | } |
| 214 | } |