1a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
2a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com/*
3a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com * Copyright 2012 Google Inc.
4a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com *
5a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com * Use of this source code is governed by a BSD-style license that can be
6a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com * found in the LICENSE file.
7a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com */
8a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
9a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
10a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com#include "gl/GrGLInterface.h"
11603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrDebugGL.h"
12603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrShaderObj.h"
13603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrProgramObj.h"
14603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrBufferObj.h"
15603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrTextureUnitObj.h"
16603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrTextureObj.h"
17603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrFrameBufferObj.h"
18603687589970f5984b4c2fd42e76f443215137barobertphillips@google.com#include "GrRenderBufferObj.h"
196ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com#include "GrVertexArrayObj.h"
2072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com#include "SkFloatingPoint.h"
215e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com#include "../GrGLNoOpInterface.h"
22a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
235e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.comnamespace { // suppress no previous prototype warning
247aabfa4db3b7f851b772a3fab9446ab58e995d34caryclark@google.com
25a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
26dc9cbfdf011a1b8bb7dcd4f046345e4a06ece22arobertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLActiveTexture(GrGLenum texture) {
27935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
2801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    // Ganesh offsets the texture unit indices
2901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    texture -= GR_GL_TEXTURE0;
3001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    GrAlwaysAssert(texture < GrDebugGL::getInstance()->getMaxTextureUnits());
31a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
32a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrDebugGL::getInstance()->setCurTextureUnit(texture);
33a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
34a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
35a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.orgGrGLvoid GR_GL_FUNCTION_TYPE debugGLClientActiveTexture(GrGLenum texture) {
36a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org
37a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    // Ganesh offsets the texture unit indices
38a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    texture -= GR_GL_TEXTURE0;
39a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    GrAlwaysAssert(texture < GrDebugGL::getInstance()->getMaxTextureUnits());
40a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org}
41a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org
42a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
43935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLAttachShader(GrGLuint programID,
44b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                 GrGLuint shaderID) {
4501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
46935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrProgramObj *program = GR_FIND(programID, GrProgramObj,
47b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                    GrDebugGL::kProgram_ObjTypes);
48a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(program);
49a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
50935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrShaderObj *shader = GR_FIND(shaderID,
51935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                  GrShaderObj,
52b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                  GrDebugGL::kShader_ObjTypes);
53a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(shader);
54a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
55a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    program->AttachShader(shader);
56a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
57a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
58b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBeginQuery(GrGLenum target, GrGLuint id) {
59b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com}
60b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
61935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBindAttribLocation(GrGLuint program,
62935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                       GrGLuint index,
63b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                       const char* name) {
64b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com}
6501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
6601ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
67935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBindTexture(GrGLenum target,
68b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                GrGLuint textureID) {
6901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
7001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    // we don't use cube maps
71935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(target == GR_GL_TEXTURE_2D);
72b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                    // || target == GR_GL_TEXTURE_CUBE_MAP);
7301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
7401ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    // a textureID of 0 is acceptable - it binds to the default texture target
75935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
76b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                    GrDebugGL::kTexture_ObjTypes);
7701ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
7801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    GrDebugGL::getInstance()->setTexture(texture);
7901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com}
8001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
81a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
82a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
83935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBufferData(GrGLenum target,
84935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLsizeiptr size,
85935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               const GrGLvoid* data,
8693a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com                                               GrGLenum usage) {
87935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
88b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_ELEMENT_ARRAY_BUFFER == target);
89a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(size >= 0);
90935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_STREAM_DRAW == usage ||
91935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                   GR_GL_STATIC_DRAW == usage ||
92b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_DYNAMIC_DRAW == usage);
93a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
94a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrBufferObj *buffer = NULL;
95a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (target) {
96a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ARRAY_BUFFER:
97a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getArrayBuffer();
98a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
99a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ELEMENT_ARRAY_BUFFER:
100a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
101a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
102a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        default:
103a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrCrash("Unexpected target to glBufferData");
104a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
105a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
106a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
107a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(buffer);
108a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(buffer->getBound());
109a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
110dc9cbfdf011a1b8bb7dcd4f046345e4a06ece22arobertphillips@google.com    buffer->allocate(size, reinterpret_cast<const GrGLchar *>(data));
111a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    buffer->setUsage(usage);
112a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
113a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
114b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
115935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLPixelStorei(GrGLenum pname,
116b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                GrGLint param) {
11772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
11872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    switch (pname) {
11972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_UNPACK_ROW_LENGTH:
12072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrDebugGL::getInstance()->setUnPackRowLength(param);
12172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
12272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_PACK_ROW_LENGTH:
12372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrDebugGL::getInstance()->setPackRowLength(param);
12472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
12572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_UNPACK_ALIGNMENT:
12672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
12772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_PACK_ALIGNMENT:
12872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrAlwaysAssert(false);
12972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
13072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        default:
13172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrAlwaysAssert(false);
13272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
13372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
13472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com}
135b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
136935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLReadPixels(GrGLint x,
137935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLint y,
138935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLsizei width,
139935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLsizei height,
140935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLenum format,
141935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrGLenum type,
14272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com                                               GrGLvoid* pixels) {
14372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
14472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLint pixelsInRow = width;
14572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    if (0 < GrDebugGL::getInstance()->getPackRowLength()) {
14672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        pixelsInRow = GrDebugGL::getInstance()->getPackRowLength();
14772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
14872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
14972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLint componentsPerPixel = 0;
15072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
15172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    switch (format) {
15272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_RGBA:
15372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            // fallthrough
15472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_BGRA:
15572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            componentsPerPixel = 4;
15672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
15772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_RGB:
15872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            componentsPerPixel = 3;
15972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
1609da653185c7be41b26eeb408d0c0d0a67e02d857robertphillips@google.com        case GR_GL_RED:
1619da653185c7be41b26eeb408d0c0d0a67e02d857robertphillips@google.com            componentsPerPixel = 1;
1629da653185c7be41b26eeb408d0c0d0a67e02d857robertphillips@google.com            break;
16372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        default:
16472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrAlwaysAssert(false);
16572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
16672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
16772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
16872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLint alignment = 4;  // the pack alignment (one of 1, 2, 4 or 8)
16972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    // Ganesh currently doesn't support setting GR_GL_PACK_ALIGNMENT
17072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
17172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLint componentSize = 0;  // size (in bytes) of a single component
17272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
17372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    switch (type) {
17472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        case GR_GL_UNSIGNED_BYTE:
17572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            componentSize = 1;
17672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
17772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        default:
17872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            GrAlwaysAssert(false);
17972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com            break;
18072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
18172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
18272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLint rowStride = 0;  // number of components (not bytes) to skip
18372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    if (componentSize >= alignment) {
18472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        rowStride = componentsPerPixel * pixelsInRow;
18572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    } else {
186935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com        float fTemp =
187935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com            sk_float_ceil(componentSize * componentsPerPixel * pixelsInRow /
18872f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com                          static_cast<float>(alignment));
18972f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        rowStride = static_cast<GrGLint>(alignment * fTemp / componentSize);
19072f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
19172f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com
19272f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    GrGLchar *scanline = static_cast<GrGLchar *>(pixels);
19372f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    for (int y = 0; y < height; ++y) {
19472f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        memset(scanline, 0, componentsPerPixel * componentSize * width);
19572f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com        scanline += rowStride;
19672f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com    }
19772f0a2948467d35053a9af6c28fea9110dcd65d0robertphillips@google.com}
198dc9cbfdf011a1b8bb7dcd4f046345e4a06ece22arobertphillips@google.com
199b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLUseProgram(GrGLuint programID) {
200b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
201b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // A programID of 0 is legal
202935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrProgramObj *program = GR_FIND(programID,
203935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                     GrProgramObj,
204b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                     GrDebugGL::kProgram_ObjTypes);
205b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
206b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrDebugGL::getInstance()->useProgram(program);
207b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
208b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
209935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindFramebuffer(GrGLenum target,
210b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                     GrGLuint frameBufferID) {
211b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
212012121d2878285bc405b4e2f0a90684d5dea407drobertphillips@google.com     GrAlwaysAssert(GR_GL_FRAMEBUFFER == target ||
213012121d2878285bc405b4e2f0a90684d5dea407drobertphillips@google.com                    GR_GL_READ_FRAMEBUFFER == target ||
214012121d2878285bc405b4e2f0a90684d5dea407drobertphillips@google.com                    GR_GL_DRAW_FRAMEBUFFER);
215b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
216935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     // a frameBufferID of 0 is acceptable - it binds to the default
217b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // frame buffer
218935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrFrameBufferObj *frameBuffer = GR_FIND(frameBufferID,
219935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                             GrFrameBufferObj,
220b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                             GrDebugGL::kFrameBuffer_ObjTypes);
221b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
222b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrDebugGL::getInstance()->setFrameBuffer(frameBuffer);
223b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
224b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
2256ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLBindRenderbuffer(GrGLenum target, GrGLuint renderBufferID) {
226b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
227b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(GR_GL_RENDERBUFFER == target);
228b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
229b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // a renderBufferID of 0 is acceptable - it unbinds the bound render buffer
230935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrRenderBufferObj *renderBuffer = GR_FIND(renderBufferID,
231935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrRenderBufferObj,
232b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                               GrDebugGL::kRenderBuffer_ObjTypes);
233b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
234b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrDebugGL::getInstance()->setRenderBuffer(renderBuffer);
235b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
236b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
2376ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteTextures(GrGLsizei n, const GrGLuint* textures) {
238b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
239b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // first potentially unbind the texture
240b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // TODO: move this into GrDebugGL as unBindTexture?
241935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     for (unsigned int i = 0;
242935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com          i < GrDebugGL::getInstance()->getMaxTextureUnits();
243b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com          ++i) {
244b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrTextureUnitObj *pTU = GrDebugGL::getInstance()->getTextureUnit(i);
245b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
246b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         if (pTU->getTexture()) {
247b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             for (int j = 0; j < n; ++j) {
248b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
249b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 if (textures[j] == pTU->getTexture()->getID()) {
250b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                     // this ID is the current texture - revert the binding to 0
251b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                     pTU->setTexture(NULL);
252b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 }
253b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
254b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         }
255b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
256b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
257b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // TODO: fuse the following block with DeleteRenderBuffers?
258935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     // Open GL will remove a deleted render buffer from the active
259b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // frame buffer but not from any other frame buffer
260b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     if (GrDebugGL::getInstance()->getFrameBuffer()) {
261b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
262b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrFrameBufferObj *frameBuffer = GrDebugGL::getInstance()->getFrameBuffer();
263b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
264b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         for (int i = 0; i < n; ++i) {
265b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
266935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getColor() &&
267b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 textures[i] == frameBuffer->getColor()->getID()) {
268b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setColor(NULL);
269935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             }
270935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getDepth() &&
271b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 textures[i] == frameBuffer->getDepth()->getID()) {
272b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setDepth(NULL);
273b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
274935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getStencil() &&
275b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 textures[i] == frameBuffer->getStencil()->getID()) {
276b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setStencil(NULL);
277b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
278b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         }
279b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
280b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
281b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // then actually "delete" the buffers
282b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     for (int i = 0; i < n; ++i) {
283935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         GrTextureObj *buffer = GR_FIND(textures[i],
284935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                        GrTextureObj,
285b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                        GrDebugGL::kTexture_ObjTypes);
286b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(buffer);
287b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
288b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         // OpenGL gives no guarantees if a texture is deleted while attached to
289b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         // something other than the currently bound frame buffer
290b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getBound());
291b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
292b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getDeleted());
293b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         buffer->deleteAction();
294b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
295b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
296b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
297b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
298935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteFramebuffers(GrGLsizei n,
299b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                        const GrGLuint *frameBuffers) {
300b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
301b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // first potentially unbind the buffers
302b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     if (GrDebugGL::getInstance()->getFrameBuffer()) {
303b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         for (int i = 0; i < n; ++i) {
304b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
305935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (frameBuffers[i] ==
306b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 GrDebugGL::getInstance()->getFrameBuffer()->getID()) {
307b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 // this ID is the current frame buffer - rebind to the default
308b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 GrDebugGL::getInstance()->setFrameBuffer(NULL);
309b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
310b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         }
311b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
312b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
313b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // then actually "delete" the buffers
314b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     for (int i = 0; i < n; ++i) {
315935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         GrFrameBufferObj *buffer = GR_FIND(frameBuffers[i],
316935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                            GrFrameBufferObj,
317b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                            GrDebugGL::kFrameBuffer_ObjTypes);
318b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(buffer);
319b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
320b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getDeleted());
321b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         buffer->deleteAction();
322b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
323b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
324b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
325935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteRenderbuffers(GrGLsizei n,
326b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                         const GrGLuint *renderBuffers) {
327b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
328b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // first potentially unbind the buffers
329b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     if (GrDebugGL::getInstance()->getRenderBuffer()) {
330b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         for (int i = 0; i < n; ++i) {
331b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
332935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (renderBuffers[i] ==
333b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 GrDebugGL::getInstance()->getRenderBuffer()->getID()) {
334935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                 // this ID is the current render buffer - make no
335b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 // render buffer be bound
336b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 GrDebugGL::getInstance()->setRenderBuffer(NULL);
337b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
338b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         }
339b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
340b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
341b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // TODO: fuse the following block with DeleteTextures?
342935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     // Open GL will remove a deleted render buffer from the active frame
343b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // buffer but not from any other frame buffer
344b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     if (GrDebugGL::getInstance()->getFrameBuffer()) {
345b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
346935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         GrFrameBufferObj *frameBuffer =
347b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                               GrDebugGL::getInstance()->getFrameBuffer();
348b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
349b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         for (int i = 0; i < n; ++i) {
350b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
351935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getColor() &&
352b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 renderBuffers[i] == frameBuffer->getColor()->getID()) {
353b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setColor(NULL);
354935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             }
355935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getDepth() &&
356b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 renderBuffers[i] == frameBuffer->getDepth()->getID()) {
357b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setDepth(NULL);
358b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
359935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com             if (NULL != frameBuffer->getStencil() &&
360b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 renderBuffers[i] == frameBuffer->getStencil()->getID()) {
361b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                 frameBuffer->setStencil(NULL);
362b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com             }
363b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         }
364b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
365b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
366b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // then actually "delete" the buffers
367b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     for (int i = 0; i < n; ++i) {
368935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         GrRenderBufferObj *buffer = GR_FIND(renderBuffers[i],
369935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                             GrRenderBufferObj,
370b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                             GrDebugGL::kRenderBuffer_ObjTypes);
371b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(buffer);
372b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
373935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         // OpenGL gives no guarantees if a render buffer is deleted
374935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         // while attached to something other than the currently
375b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         // bound frame buffer
376b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getColorBound());
377b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getDepthBound());
378c1dd8787af1c5da4673de3544965aba382164995commit-bot@chromium.org         // However, at GrContext destroy time we release all GrRsources and so stencil buffers
379c1dd8787af1c5da4673de3544965aba382164995commit-bot@chromium.org         // may get deleted before FBOs that refer to them.
380c1dd8787af1c5da4673de3544965aba382164995commit-bot@chromium.org         //GrAlwaysAssert(!buffer->getStencilBound());
381b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
382b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!buffer->getDeleted());
383b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         buffer->deleteAction();
384b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
385b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
386b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
387935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferRenderbuffer(GrGLenum target,
388935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                             GrGLenum attachment,
389935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                             GrGLenum renderbuffertarget,
390b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                             GrGLuint renderBufferID) {
391b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
392b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
393935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
394935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                    GR_GL_DEPTH_ATTACHMENT == attachment ||
395b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                    GR_GL_STENCIL_ATTACHMENT == attachment);
396b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(GR_GL_RENDERBUFFER == renderbuffertarget);
397b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
398b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
399b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // A render buffer cannot be attached to the default framebuffer
400b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(NULL != framebuffer);
401b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
402935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     // a renderBufferID of 0 is acceptable - it unbinds the current
403b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // render buffer
404935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrRenderBufferObj *renderbuffer = GR_FIND(renderBufferID,
405935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                               GrRenderBufferObj,
406b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                               GrDebugGL::kRenderBuffer_ObjTypes);
407b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
408b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     switch (attachment) {
409b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_COLOR_ATTACHMENT0:
410b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setColor(renderbuffer);
411b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
412b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_DEPTH_ATTACHMENT:
413b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setDepth(renderbuffer);
414b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
415b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_STENCIL_ATTACHMENT:
416b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setStencil(renderbuffer);
417b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
418b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     default:
419b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(false);
420b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
421b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     };
422b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
423b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
424b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
425b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com ////////////////////////////////////////////////////////////////////////////////
426935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com GrGLvoid GR_GL_FUNCTION_TYPE debugGLFramebufferTexture2D(GrGLenum target,
427935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                          GrGLenum attachment,
428935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                          GrGLenum textarget,
429935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                          GrGLuint textureID,
430b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                          GrGLint level) {
431b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
432b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(GR_GL_FRAMEBUFFER == target);
433935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrAlwaysAssert(GR_GL_COLOR_ATTACHMENT0 == attachment ||
434935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                    GR_GL_DEPTH_ATTACHMENT == attachment ||
435b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                    GR_GL_STENCIL_ATTACHMENT == attachment);
436b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(GR_GL_TEXTURE_2D == textarget);
437b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
438b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrFrameBufferObj *framebuffer = GrDebugGL::getInstance()->getFrameBuffer();
439b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // A texture cannot be attached to the default framebuffer
440b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(NULL != framebuffer);
441b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
442b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     // A textureID of 0 is allowed - it unbinds the currently bound texture
443935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com     GrTextureObj *texture = GR_FIND(textureID, GrTextureObj,
444b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                     GrDebugGL::kTexture_ObjTypes);
445b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     if (texture) {
446935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com         // The texture shouldn't be bound to a texture unit - this
447b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         // could lead to a feedback loop
448b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(!texture->getBound());
449b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     }
450b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
451b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     GrAlwaysAssert(0 == level);
452b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
453b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     switch (attachment) {
454b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_COLOR_ATTACHMENT0:
455b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setColor(texture);
456b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
457b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_DEPTH_ATTACHMENT:
458b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setDepth(texture);
459b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
460b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     case GR_GL_STENCIL_ATTACHMENT:
461b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         framebuffer->setStencil(texture);
462b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
463b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     default:
464b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         GrAlwaysAssert(false);
465b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com         break;
466b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com     };
467b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com }
468b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com
469a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comGrGLuint GR_GL_FUNCTION_TYPE debugGLCreateProgram() {
470a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
471935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrProgramObj *program = GR_CREATE(GrProgramObj,
472b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                      GrDebugGL::kProgram_ObjTypes);
473a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
474a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    return program->getID();
475a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
476a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
477a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comGrGLuint GR_GL_FUNCTION_TYPE debugGLCreateShader(GrGLenum type) {
478935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com
479935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_VERTEX_SHADER == type ||
480b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_FRAGMENT_SHADER == type);
481a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
48201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    GrShaderObj *shader = GR_CREATE(GrShaderObj, GrDebugGL::kShader_ObjTypes);
48301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    shader->setType(type);
484a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
485a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    return shader->getID();
486a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
487a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
488a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteProgram(GrGLuint programID) {
489a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
490935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrProgramObj *program = GR_FIND(programID,
491935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                    GrProgramObj,
492b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                    GrDebugGL::kProgram_ObjTypes);
493a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(program);
494a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
495a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    if (program->getRefCount()) {
496a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        // someone is still using this program so we can't delete it here
497a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        program->setMarkedForDeletion();
498a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    } else {
499a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        program->deleteAction();
500a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
501a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
502a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
503a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteShader(GrGLuint shaderID) {
504a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
505935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrShaderObj *shader = GR_FIND(shaderID,
506935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                  GrShaderObj,
507b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                  GrDebugGL::kShader_ObjTypes);
508a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(shader);
509a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
510a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    if (shader->getRefCount()) {
511a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        // someone is still using this shader so we can't delete it here
512a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        shader->setMarkedForDeletion();
513a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    } else {
514a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        shader->deleteAction();
515a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
516a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
517a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
518935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid debugGenObjs(GrDebugGL::GrObjTypes type,
519935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                      GrGLsizei n,
520b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                      GrGLuint* ids) {
521a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
52201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com   for (int i = 0; i < n; ++i) {
52301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com        GrFakeRefObj *obj = GrDebugGL::getInstance()->createObj(type);
52401ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com        GrAlwaysAssert(obj);
52501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com        ids[i] = obj->getID();
526a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
527a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
528a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
52901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenBuffers(GrGLsizei n, GrGLuint* ids) {
53001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    debugGenObjs(GrDebugGL::kBuffer_ObjTypes, n, ids);
53101ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com}
53201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
533a67b348f7f66678e392b0f9e70cc738cc0c69007commit-bot@chromium.orgGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenerateMipmap(GrGLenum level) {
534a67b348f7f66678e392b0f9e70cc738cc0c69007commit-bot@chromium.org}
535a67b348f7f66678e392b0f9e70cc738cc0c69007commit-bot@chromium.org
536935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenFramebuffers(GrGLsizei n,
537b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                    GrGLuint* ids) {
53801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    debugGenObjs(GrDebugGL::kFrameBuffer_ObjTypes, n, ids);
539dc9cbfdf011a1b8bb7dcd4f046345e4a06ece22arobertphillips@google.com}
540dc9cbfdf011a1b8bb7dcd4f046345e4a06ece22arobertphillips@google.com
541935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenRenderbuffers(GrGLsizei n,
542b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                     GrGLuint* ids) {
54301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    debugGenObjs(GrDebugGL::kRenderBuffer_ObjTypes, n, ids);
54401ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com}
54501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
54601ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenTextures(GrGLsizei n, GrGLuint* ids) {
54724abe97bef3fdf10e7811e0deea765ce5fc50232bsalomon@google.com    debugGenObjs(GrDebugGL::kTexture_ObjTypes, n, ids);
54813c9a8e201110ae355bedf60e587a4b9de2a3298bsalomon@google.com}
54913c9a8e201110ae355bedf60e587a4b9de2a3298bsalomon@google.com
5506ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGenVertexArrays(GrGLsizei n, GrGLuint* ids) {
5516ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    debugGenObjs(GrDebugGL::kVertexArray_ObjTypes, n, ids);
5526ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com}
55313c9a8e201110ae355bedf60e587a4b9de2a3298bsalomon@google.com
5546ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteVertexArrays(GrGLsizei n, const GrGLuint* ids) {
5556ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    for (GrGLsizei i = 0; i < n; ++i) {
5566ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        GrVertexArrayObj* array =
5576ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com            GR_FIND(ids[i], GrVertexArrayObj, GrDebugGL::kVertexArray_ObjTypes);
5586ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        GrAlwaysAssert(array);
5596ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com
5606ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        // Deleting the current vertex array binds object 0
5616ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        if (GrDebugGL::getInstance()->getVertexArray() == array) {
5626ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com            GrDebugGL::getInstance()->setVertexArray(NULL);
5636ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        }
5646ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com
5656ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        if (array->getRefCount()) {
5666ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com            // someone is still using this vertex array so we can't delete it here
5676ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com            array->setMarkedForDeletion();
5686ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        } else {
5696ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com            array->deleteAction();
5706ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com        }
5716ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    }
5726ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com}
5736ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com
5746ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBindVertexArray(GrGLuint id) {
5756ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    GrVertexArrayObj* array = GR_FIND(id, GrVertexArrayObj, GrDebugGL::kVertexArray_ObjTypes);
5763f177e9cbcd94d9fc9d969591cc939a81d16d111bsalomon@google.com    GrAlwaysAssert((0 == id) || NULL != array);
5776ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    GrDebugGL::getInstance()->setVertexArray(array);
5786ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com}
5796ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com
5806ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLBindBuffer(GrGLenum target, GrGLuint bufferID) {
5816ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target || GR_GL_ELEMENT_ARRAY_BUFFER == target);
582a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
583935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrBufferObj *buffer = GR_FIND(bufferID,
584935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                  GrBufferObj,
585b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                  GrDebugGL::kBuffer_ObjTypes);
5865e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    // 0 is a permissible bufferID - it unbinds the current buffer
587a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
588a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (target) {
589a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ARRAY_BUFFER:
590a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrDebugGL::getInstance()->setArrayBuffer(buffer);
591a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
592a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ELEMENT_ARRAY_BUFFER:
593a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrDebugGL::getInstance()->setElementArrayBuffer(buffer);
594a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
595a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        default:
596a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrCrash("Unexpected target to glBindBuffer");
597a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
598a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
599a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
600a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
601a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com// deleting a bound buffer has the side effect of binding 0
6026ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLDeleteBuffers(GrGLsizei n, const GrGLuint* ids) {
603a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    // first potentially unbind the buffers
604a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    for (int i = 0; i < n; ++i) {
605a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
606935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com        if (GrDebugGL::getInstance()->getArrayBuffer() &&
607a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            ids[i] == GrDebugGL::getInstance()->getArrayBuffer()->getID()) {
608a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            // this ID is the current array buffer
609a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrDebugGL::getInstance()->setArrayBuffer(NULL);
610a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        }
611935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com        if (GrDebugGL::getInstance()->getElementArrayBuffer() &&
612935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com            ids[i] ==
613b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                GrDebugGL::getInstance()->getElementArrayBuffer()->getID()) {
614a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            // this ID is the current element array buffer
615a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrDebugGL::getInstance()->setElementArrayBuffer(NULL);
616a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        }
617a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
618a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
619a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    // then actually "delete" the buffers
620a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    for (int i = 0; i < n; ++i) {
621935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com        GrBufferObj *buffer = GR_FIND(ids[i],
622935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                      GrBufferObj,
623b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                      GrDebugGL::kBuffer_ObjTypes);
624a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        GrAlwaysAssert(buffer);
625a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
626a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        GrAlwaysAssert(!buffer->getDeleted());
627a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        buffer->deleteAction();
628a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
629a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
630a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
631a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com// map a buffer to the caller's address space
6326ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.comGrGLvoid* GR_GL_FUNCTION_TYPE debugGLMapBuffer(GrGLenum target, GrGLenum access) {
633a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
634935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
635b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_ELEMENT_ARRAY_BUFFER == target);
636b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com    // GR_GL_READ_ONLY == access ||  || GR_GL_READ_WRIT == access);
637935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_WRITE_ONLY == access);
638a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
639a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrBufferObj *buffer = NULL;
640a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (target) {
641a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ARRAY_BUFFER:
642a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getArrayBuffer();
643a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
644a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ELEMENT_ARRAY_BUFFER:
645a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
646a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
647a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        default:
648a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrCrash("Unexpected target to glMapBuffer");
649a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
650a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
651a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
652a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    if (buffer) {
653a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        GrAlwaysAssert(!buffer->getMapped());
654a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        buffer->setMapped();
655a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        return buffer->getDataPtr();
656a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
657a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
658a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(false);
659a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    return NULL;        // no buffer bound to the target
660a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
661a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
662a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com// remove a buffer from the caller's address space
663935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com// TODO: check if the "access" method from "glMapBuffer" was honored
664a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comGrGLboolean GR_GL_FUNCTION_TYPE debugGLUnmapBuffer(GrGLenum target) {
665a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
666935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
667b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_ELEMENT_ARRAY_BUFFER == target);
668a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
669a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrBufferObj *buffer = NULL;
670a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (target) {
671a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ARRAY_BUFFER:
672a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getArrayBuffer();
673a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
674a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ELEMENT_ARRAY_BUFFER:
675a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
676a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
677a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        default:
678a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrCrash("Unexpected target to glUnmapBuffer");
679a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
680a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
681a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
682a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    if (buffer) {
683a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        GrAlwaysAssert(buffer->getMapped());
684a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        buffer->resetMapped();
685a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        return GR_GL_TRUE;
686a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
687a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
688a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(false);
689a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    return GR_GL_FALSE; // GR_GL_INVALID_OPERATION;
690a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
691a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
692935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.comGrGLvoid GR_GL_FUNCTION_TYPE debugGLGetBufferParameteriv(GrGLenum target,
693935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com                                                         GrGLenum value,
694b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                                                         GrGLint* params) {
695a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
696935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_ARRAY_BUFFER == target ||
697b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_ELEMENT_ARRAY_BUFFER == target);
698935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    GrAlwaysAssert(GR_GL_BUFFER_SIZE == value ||
699b1bb8a3652c5bbd0331448b1f2950d1cb2f24aa5robertphillips@google.com                   GR_GL_BUFFER_USAGE == value);
700a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
701a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrBufferObj *buffer = NULL;
702a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (target) {
703a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ARRAY_BUFFER:
704a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getArrayBuffer();
705a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
706a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_ELEMENT_ARRAY_BUFFER:
707a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            buffer = GrDebugGL::getInstance()->getElementArrayBuffer();
708935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com            break;
709a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
710a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
711a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    GrAlwaysAssert(buffer);
712a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com
713a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    switch (value) {
714a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_BUFFER_MAPPED:
715a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            *params = GR_GL_FALSE;
716a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            if (buffer)
717a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com                *params = buffer->getMapped() ? GR_GL_TRUE : GR_GL_FALSE;
718a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
719a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_BUFFER_SIZE:
720a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            *params = 0;
721a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            if (buffer)
722a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com                *params = buffer->getSize();
723a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
724a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        case GR_GL_BUFFER_USAGE:
725a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            *params = GR_GL_STATIC_DRAW;
726a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            if (buffer)
727a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com                *params = buffer->getUsage();
728a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
729a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com        default:
730a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            GrCrash("Unexpected value to glGetBufferParamateriv");
731a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com            break;
732a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com    }
733a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com};
7347aabfa4db3b7f851b772a3fab9446ab58e995d34caryclark@google.com} // end of namespace
7357aabfa4db3b7f851b772a3fab9446ab58e995d34caryclark@google.com
73601ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
73701ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.comstruct GrDebugGLInterface : public GrGLInterface {
73801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
73901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.compublic:
74093a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    SK_DECLARE_INST_COUNT(GrDebugGLInterface)
74193a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com
74201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    GrDebugGLInterface()
74301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com        : fWrapped(NULL) {
744ab8e565ff2aa849901f924f9fba827c80e093e7crobertphillips@google.com        GrDebugGL::staticRef();
745ab8e565ff2aa849901f924f9fba827c80e093e7crobertphillips@google.com    }
746ab8e565ff2aa849901f924f9fba827c80e093e7crobertphillips@google.com
747ab8e565ff2aa849901f924f9fba827c80e093e7crobertphillips@google.com    virtual ~GrDebugGLInterface() {
748ab8e565ff2aa849901f924f9fba827c80e093e7crobertphillips@google.com        GrDebugGL::staticUnRef();
74901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    }
75001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
75101ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    void setWrapped(GrGLInterface *interface) {
75201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com        fWrapped.reset(interface);
75301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    }
75401ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
75501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    // TODO: there are some issues w/ wrapping another GL interface inside the
75601ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    // debug interface:
75701ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      Since none of the "gl" methods are member functions they don't get
75801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      a "this" pointer through which to access "fWrapped"
759935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      This could be worked around by having all of them access the
760935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      "glInterface" pointer - i.e., treating the debug interface as a
76101ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      true singleton
76201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //
763935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      The problem with this is that we also want to handle OpenGL
764935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      contexts. The natural way to do this is to have multiple debug
765935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      interfaces. Each of which represents a separate context. The
766935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      static ID count would still uniquify IDs across all of them.
767935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      The problem then is that we couldn't treat the debug GL
768935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      interface as a singleton (since there would be one for each
76901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      context).
77001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //
771935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      The solution to this is probably to alter SkDebugGlContext's
772935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      "makeCurrent" method to make a call like "makeCurrent(this)" to
773935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      the debug GL interface (assuming that the application will create
774860f3b88452e3dd2cf47282f1a1527e8876d41e1robertphillips@google.com    //      multiple SkGLContextHelper's) to let it switch between the active
775935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      context. Everything in the GrDebugGL object would then need to be
776935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      moved to a GrContextObj and the GrDebugGL object would just switch
777935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    //      between them. Note that this approach would also require that
77801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      SkDebugGLContext wrap an arbitrary other context
77901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    //      and then pass the wrapped interface to the debug GL interface.
78001ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
78101ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.comprotected:
78201ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.comprivate:
78301ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
78401ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    SkAutoTUnref<GrGLInterface> fWrapped;
78501ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
78601ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com    typedef GrGLInterface INHERITED;
78701ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com};
78801ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com
78901ac33fb163cf5856dab05c5981085503f3ffc71robertphillips@google.com////////////////////////////////////////////////////////////////////////////////
790a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.comconst GrGLInterface* GrGLCreateDebugInterface() {
79193a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    GrGLInterface* interface = SkNEW(GrDebugGLInterface);
79293a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com
79393a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindingsExported = kDesktop_GrGLBinding;
79493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fActiveTexture = debugGLActiveTexture;
79593a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fAttachShader = debugGLAttachShader;
79693a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBeginQuery = debugGLBeginQuery;
79793a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindAttribLocation = debugGLBindAttribLocation;
79893a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindBuffer = debugGLBindBuffer;
7995e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fBindFragDataLocation = noOpGLBindFragDataLocation;
80093a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindTexture = debugGLBindTexture;
8016ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    interface->fBindVertexArray = debugGLBindVertexArray;
8025e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fBlendColor = noOpGLBlendColor;
8035e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fBlendFunc = noOpGLBlendFunc;
80493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBufferData = debugGLBufferData;
8055e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fBufferSubData = noOpGLBufferSubData;
8065e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fClear = noOpGLClear;
8075e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fClearColor = noOpGLClearColor;
8085e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fClearStencil = noOpGLClearStencil;
809a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fClientActiveTexture = debugGLClientActiveTexture;
8105e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fColorMask = noOpGLColorMask;
8115e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fCompileShader = noOpGLCompileShader;
8125e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fCompressedTexImage2D = noOpGLCompressedTexImage2D;
81388672fbe426b68b6981a96204de8aff8201dd29ccommit-bot@chromium.org    interface->fCopyTexSubImage2D = noOpGLCopyTexSubImage2D;
81493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fCreateProgram = debugGLCreateProgram;
81593a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fCreateShader = debugGLCreateShader;
8165e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fCullFace = noOpGLCullFace;
81793a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteBuffers = debugGLDeleteBuffers;
81893a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteProgram = debugGLDeleteProgram;
8195e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDeleteQueries = noOpGLDeleteIds;
82093a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteShader = debugGLDeleteShader;
82193a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteTextures = debugGLDeleteTextures;
8226ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    interface->fDeleteVertexArrays = debugGLDeleteVertexArrays;
8235e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDepthMask = noOpGLDepthMask;
8245e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDisable = noOpGLDisable;
825a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fDisableClientState = noOpGLDisableClientState;
8265e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDisableVertexAttribArray = noOpGLDisableVertexAttribArray;
8275e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDrawArrays = noOpGLDrawArrays;
8285e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDrawBuffer = noOpGLDrawBuffer;
8295e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDrawBuffers = noOpGLDrawBuffers;
8305e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fDrawElements = noOpGLDrawElements;
8315e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fEnable = noOpGLEnable;
832a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fEnableClientState = noOpGLEnableClientState;
8335e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fEnableVertexAttribArray = noOpGLEnableVertexAttribArray;
8345e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fEndQuery = noOpGLEndQuery;
8355e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fFinish = noOpGLFinish;
8365e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fFlush = noOpGLFlush;
8375e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fFrontFace = noOpGLFrontFace;
838a67b348f7f66678e392b0f9e70cc738cc0c69007commit-bot@chromium.org    interface->fGenerateMipmap = debugGLGenerateMipmap;
83993a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fGenBuffers = debugGLGenBuffers;
8405e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGenQueries = noOpGLGenIds;
84193a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fGenTextures = debugGLGenTextures;
84293a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fGetBufferParameteriv = debugGLGetBufferParameteriv;
8435e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetError = noOpGLGetError;
8445e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetIntegerv = noOpGLGetIntegerv;
8455e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetQueryObjecti64v = noOpGLGetQueryObjecti64v;
8465e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetQueryObjectiv = noOpGLGetQueryObjectiv;
8475e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetQueryObjectui64v = noOpGLGetQueryObjectui64v;
8485e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetQueryObjectuiv = noOpGLGetQueryObjectuiv;
8495e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetQueryiv = noOpGLGetQueryiv;
8505e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetProgramInfoLog = noOpGLGetInfoLog;
8515e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetProgramiv = noOpGLGetShaderOrProgramiv;
8525e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetShaderInfoLog = noOpGLGetInfoLog;
8535e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetShaderiv = noOpGLGetShaderOrProgramiv;
8545e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetString = noOpGLGetString;
85586c972c88eedf604db60ec44e32cefe9baf70243bsalomon@google.com    interface->fGetStringi = noOpGLGetStringi;
8565e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetTexLevelParameteriv = noOpGLGetTexLevelParameteriv;
8575e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetUniformLocation = noOpGLGetUniformLocation;
8586ccccc065b1122fec12480699d10e7e7482a8b76bsalomon@google.com    interface->fGenVertexArrays = debugGLGenVertexArrays;
859a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fLoadIdentity = noOpGLLoadIdentity;
860a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fLoadMatrixf = noOpGLLoadMatrixf;
8615e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fLineWidth = noOpGLLineWidth;
8625e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fLinkProgram = noOpGLLinkProgram;
863a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fMatrixMode = noOpGLMatrixMode;
86493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fPixelStorei = debugGLPixelStorei;
8655e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fQueryCounter = noOpGLQueryCounter;
8665e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fReadBuffer = noOpGLReadBuffer;
86793a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fReadPixels = debugGLReadPixels;
8685e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fScissor = noOpGLScissor;
8695e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fShaderSource = noOpGLShaderSource;
8705e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilFunc = noOpGLStencilFunc;
8715e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilFuncSeparate = noOpGLStencilFuncSeparate;
8725e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilMask = noOpGLStencilMask;
8735e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilMaskSeparate = noOpGLStencilMaskSeparate;
8745e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilOp = noOpGLStencilOp;
8755e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fStencilOpSeparate = noOpGLStencilOpSeparate;
876a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fTexGenf = noOpGLTexGenf;
877a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fTexGenfv = noOpGLTexGenfv;
878a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fTexGeni = noOpGLTexGeni;
8795e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fTexImage2D = noOpGLTexImage2D;
8805e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fTexParameteri = noOpGLTexParameteri;
8815e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fTexParameteriv = noOpGLTexParameteriv;
8825e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fTexSubImage2D = noOpGLTexSubImage2D;
8835e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fTexStorage2D = noOpGLTexStorage2D;
884f42e87e4b463783cad932357458ef6cc5510d774robertphillips@google.com    interface->fDiscardFramebuffer = noOpGLDiscardFramebuffer;
8855e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform1f = noOpGLUniform1f;
8865e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform1i = noOpGLUniform1i;
8875e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform1fv = noOpGLUniform1fv;
8885e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform1iv = noOpGLUniform1iv;
8895e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform2f = noOpGLUniform2f;
8905e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform2i = noOpGLUniform2i;
8915e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform2fv = noOpGLUniform2fv;
8925e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform2iv = noOpGLUniform2iv;
8935e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform3f = noOpGLUniform3f;
8945e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform3i = noOpGLUniform3i;
8955e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform3fv = noOpGLUniform3fv;
8965e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform3iv = noOpGLUniform3iv;
8975e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform4f = noOpGLUniform4f;
8985e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform4i = noOpGLUniform4i;
8995e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform4fv = noOpGLUniform4fv;
9005e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniform4iv = noOpGLUniform4iv;
9015e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniformMatrix2fv = noOpGLUniformMatrix2fv;
9025e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniformMatrix3fv = noOpGLUniformMatrix3fv;
9035e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fUniformMatrix4fv = noOpGLUniformMatrix4fv;
90493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fUseProgram = debugGLUseProgram;
9055e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fVertexAttrib4fv = noOpGLVertexAttrib4fv;
9065e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fVertexAttribPointer = noOpGLVertexAttribPointer;
907a4da2893bba74445b29b326a90106b3908dcf8e0commit-bot@chromium.org    interface->fVertexPointer = noOpGLVertexPointer;
9085e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fViewport = noOpGLViewport;
90993a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindFramebuffer = debugGLBindFramebuffer;
91093a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fBindRenderbuffer = debugGLBindRenderbuffer;
9115e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fCheckFramebufferStatus = noOpGLCheckFramebufferStatus;
91293a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteFramebuffers = debugGLDeleteFramebuffers;
91393a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fDeleteRenderbuffers = debugGLDeleteRenderbuffers;
91493a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fFramebufferRenderbuffer = debugGLFramebufferRenderbuffer;
91593a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fFramebufferTexture2D = debugGLFramebufferTexture2D;
91693a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fGenFramebuffers = debugGLGenFramebuffers;
91793a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fGenRenderbuffers = debugGLGenRenderbuffers;
918935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    interface->fGetFramebufferAttachmentParameteriv =
9195e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com                                    noOpGLGetFramebufferAttachmentParameteriv;
9205e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fGetRenderbufferParameteriv = noOpGLGetRenderbufferParameteriv;
9215e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fRenderbufferStorage = noOpGLRenderbufferStorage;
922935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    interface->fRenderbufferStorageMultisample =
9235e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com                                    noOpGLRenderbufferStorageMultisample;
9245e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com    interface->fBlitFramebuffer = noOpGLBlitFramebuffer;
925935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    interface->fResolveMultisampleFramebuffer =
9265e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com                                    noOpGLResolveMultisampleFramebuffer;
92793a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fMapBuffer = debugGLMapBuffer;
92893a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    interface->fUnmapBuffer = debugGLUnmapBuffer;
929935e9f4fafdfc64130e6be9ea2bb30e3bafd852armistry@google.com    interface->fBindFragDataLocationIndexed =
9305e75899d77a86ebaf460ca82ddd8ce6a62701a30bsalomon@google.com                                    noOpGLBindFragDataLocationIndexed;
93193a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com
93293a1f61a3ab9c2b8cdc4762a10254750b4777263robertphillips@google.com    return interface;
933a652541bb88249e5757315e6ee6d6ce65d3027e7robertphillips@google.com}
934