summaryrefslogtreecommitdiffstats
path: root/app/gfx/gl/gl_bindings_skia.cc
blob: fe484a612a8db850906bd763017d4d6b8e2e220e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#include "app/gfx/gl/gl_bindings_skia.h"

#include "app/gfx/gl/gl_bindings.h"
#include "app/gfx/gl/gl_implementation.h"
#include "base/logging.h"

// Skia is built against the headers in gpu\GLES.  These functions
// are exported without any call-type modifiers.
#define GR_GL_FUNCTION_TYPE

#include "third_party/skia/gpu/include/GrGLInterface.h"

namespace {

extern "C" {

// The following stub functions are required because the glXXX routines exported
// via gl_bindings.h use call-type GL_BINDING_CALL, which on Windows is stdcall.
// Skia has been built against the GLES headers, so the interfaces in
// GrGLInterface are __cdecl.

GLvoid StubGLActiveTexture(GLenum texture) {
  glActiveTexture(texture);
}

GLvoid StubGLAttachShader(GLuint program, GLuint shader) {
  glAttachShader(program, shader);
}

GLvoid StubGLBindAttribLocation(GLuint program, GLuint index,
                                const char* name) {
  glBindAttribLocation(program, index, name);
}

GLvoid StubGLBindBuffer(GLenum target, GLuint buffer) {
  glBindBuffer(target, buffer);
}

GLvoid StubGLBindFramebuffer(GLenum target, GLuint framebuffer) {
  glBindFramebufferEXT(target, framebuffer);
}

GLvoid StubGLBindRenderbuffer(GLenum target, GLuint renderbuffer) {
  glBindRenderbufferEXT(target, renderbuffer);
}

GLvoid StubGLBindTexture(GLenum target, GLuint texture) {
  glBindTexture(target, texture);
}

GLvoid StubGLBlendColor(GLclampf red, GLclampf green, GLclampf blue,
                        GLclampf alpha) {
  glBlendColor(red, green, blue, alpha);
}

GLvoid StubGLBlendFunc(GLenum sfactor, GLenum dfactor) {
  glBlendFunc(sfactor, dfactor);
}

GLvoid StubGLBlitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
                             GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
                             GLbitfield mask, GLenum filter) {
  glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1,
                       mask, filter);
}

GLvoid StubGLBufferData(GLenum target, GLsizei size, const void* data,
                        GLenum usage) {
  glBufferData(target, size, data, usage);
}

GLvoid StubGLBufferSubData(GLenum target, GLint offset, GLsizei size,
                           const void* data) {
  glBufferSubData(target, offset, size, data);
}

GLenum StubGLCheckFramebufferStatus(GLenum target) {
  return glCheckFramebufferStatusEXT(target);
}

GLvoid StubGLClear(GLbitfield mask) {
  glClear(mask);
}

GLvoid StubGLClearColor(GLclampf red, GLclampf green, GLclampf blue,
                        GLclampf alpha) {
  glClearColor(red, green, blue, alpha);
}

GLvoid StubGLClearStencil(GLint s) {
  glClearStencil(s);
}

GLvoid StubGLColorMask(GLboolean red, GLboolean green, GLboolean blue,
                       GLboolean alpha) {
  glColorMask(red, green, blue, alpha);
}

GLvoid StubGLCompileShader(GLuint shader) {
  glCompileShader(shader);
}

GLvoid StubGLCompressedTexImage2D(GLenum target, GLint level,
                                  GLenum internalformat, GLsizei width,
                                  GLsizei height, GLint border,
                                  GLsizei imageSize, const void* data) {
  glCompressedTexImage2D(target, level, internalformat, width, height, border,
                         imageSize, data);
}

GLuint StubGLCreateProgram(void) {
  return glCreateProgram();
}

GLuint StubGLCreateShader(GLenum type) {
  return glCreateShader(type);
}

GLvoid StubGLCullFace(GLenum mode) {
  glCullFace(mode);
}

GLvoid StubGLDeleteBuffers(GLsizei n, const GLuint* buffers) {
  glDeleteBuffersARB(n, buffers);
}

GLvoid StubGLDeleteFramebuffers(GLsizei n, const GLuint* framebuffers) {
  glDeleteFramebuffersEXT(n, framebuffers);
}

GLvoid StubGLDeleteProgram(GLuint program) {
  glDeleteProgram(program);
}

GLvoid StubGLDeleteRenderbuffers(GLsizei n, const GLuint* renderbuffers) {
  glDeleteRenderbuffersEXT(n, renderbuffers);
}

GLvoid StubGLDeleteShader(GLuint shader) {
  glDeleteShader(shader);
}

GLvoid StubGLDeleteTextures(GLsizei n, const GLuint* textures) {
  glDeleteTextures(n, textures);
}

GLvoid StubGLDepthMask(GLboolean flag) {
  glDepthMask(flag);
}

GLvoid StubGLDisable(GLenum cap) {
  glDisable(cap);
}

GLvoid StubGLDisableVertexAttribArray(GLuint index) {
  glDisableVertexAttribArray(index);
}

GLvoid StubGLDrawArrays(GLenum mode, GLint first, GLsizei count) {
  glDrawArrays(mode, first, count);
}

GLvoid StubGLDrawElements(GLenum mode, GLsizei count, GLenum type,
                          const void* indices) {
  glDrawElements(mode, count, type, indices);
}

GLvoid StubGLEnable(GLenum cap) {
  glEnable(cap);
}

GLvoid StubGLEnableVertexAttribArray(GLuint index) {
  glEnableVertexAttribArray(index);
}

GLvoid StubGLFramebufferRenderbuffer(GLenum target, GLenum attachment,
                                     GLenum renderbuffertarget,
                                     GLuint renderbuffer) {
  glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget,
                               renderbuffer);
}

GLvoid StubGLFramebufferTexture2D(GLenum target, GLenum attachment,
                                  GLenum textarget, GLuint texture,
                                  GLint level) {
  glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
}

GLvoid StubGLFrontFace(GLenum mode) {
  glFrontFace(mode);
}

GLvoid StubGLGenBuffers(GLsizei n, GLuint* buffers) {
  glGenBuffersARB(n, buffers);
}

GLvoid StubGLGenFramebuffers(GLsizei n, GLuint* framebuffers) {
  glGenFramebuffersEXT(n, framebuffers);
}

GLvoid StubGLGenRenderbuffers(GLsizei n, GLuint* renderbuffers) {
  glGenRenderbuffersEXT(n, renderbuffers);
}

GLvoid StubGLGenTextures(GLsizei n, GLuint* textures) {
  glGenTextures(n, textures);
}

GLvoid StubGLGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) {
  glGetBufferParameteriv(target, pname, params);
}

GLenum StubGLGetError() {
  return glGetError();
}

GLvoid StubGLGetIntegerv(GLenum pname, GLint* params) {
  glGetIntegerv(pname, params);
}

GLvoid StubGLGetProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei* length,
                               char* infolog) {
  glGetProgramInfoLog(program, bufsize, length, infolog);
}

GLvoid StubGLGetProgramiv(GLuint program, GLenum pname, GLint* params) {
  glGetProgramiv(program, pname, params);
}

GLvoid StubGLGetShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei* length,
                              char* infolog) {
  glGetShaderInfoLog(shader, bufsize, length, infolog);
}

GLvoid StubGLGetShaderiv(GLuint shader, GLenum pname, GLint* params) {
  glGetShaderiv(shader, pname, params);
}

const GLubyte* StubGLGetString(GLenum name) {
  return glGetString(name);
}

GLint StubGLGetUniformLocation(GLuint program, const char* name) {
  return glGetUniformLocation(program, name);
}

GLvoid StubGLLineWidth(GLfloat width) {
  glLineWidth(width);
}

GLvoid StubGLLinkProgram(GLuint program) {
  glLinkProgram(program);
}

void* StubGLMapBuffer(GLenum target, GLenum access) {
  return glMapBuffer(target, access);
}

GLvoid StubGLPixelStorei(GLenum pname, GLint param) {
  glPixelStorei(pname, param);
}

GLvoid StubGLReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
                        GLenum format, GLenum type, void* pixels) {
  glReadPixels(x, y, width, height, format, type, pixels);
}

GLvoid StubGLRenderBufferStorage(GLenum target, GLenum internalformat,
                                 GLsizei width, GLsizei height) {
  glRenderbufferStorageEXT(target, internalformat, width, height);
}

GLvoid StubGLRenderbufferStorageMultisample(GLenum target, GLsizei samples,
                                            GLenum internalformat,
                                            GLsizei width, GLsizei height) {
  glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width,
                                      height);
}

GLvoid StubGLScissor(GLint x, GLint y, GLsizei width, GLsizei height) {
  glScissor(x, y, width, height);
}

GLvoid StubGLShaderSource(GLuint shader, GLsizei count, const char** str,
                          const GLint* length) {
  glShaderSource(shader, count, str, length);
}

GLvoid StubGLStencilFunc(GLenum func, GLint ref, GLuint mask) {
  glStencilFunc(func, ref, mask);
}

GLvoid StubGLStencilFuncSeparate(GLenum face, GLenum func, GLint ref,
                                 GLuint mask) {
  glStencilFuncSeparate(face, func, ref, mask);
}

GLvoid StubGLStencilMask(GLuint mask) {
  glStencilMask(mask);
}

GLvoid StubGLStencilMaskSeparate(GLenum face, GLuint mask) {
  glStencilMaskSeparate(face, mask);
}

GLvoid StubGLStencilOp(GLenum fail, GLenum zfail, GLenum zpass) {
  glStencilOp(fail, zfail, zpass);
}

GLvoid StubGLStencilOpSeparate(GLenum face, GLenum fail, GLenum zfail,
                               GLenum zpass) {
  glStencilOpSeparate(face, fail, zfail, zpass);
}

GLvoid StubGLTexImage2D(GLenum target, GLint level, GLint internalformat,
                        GLsizei width, GLsizei height, GLint border,
                        GLenum format, GLenum type, const void* pixels) {
  glTexImage2D(target, level, internalformat, width, height, border, format,
               type, pixels);
}

GLvoid StubGLTexParameteri(GLenum target, GLenum pname, GLint param) {
  glTexParameteri(target, pname, param);
}

GLvoid StubGLTexSubImage2D(GLenum target, GLint level, GLint xoffset,
                           GLint yoffset, GLsizei width, GLsizei height,
                           GLenum format, GLenum type, const void* pixels) {
  glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type,
                  pixels);
}

GLvoid StubGLUniform1fv(GLint location, GLsizei count, const GLfloat* v) {
  glUniform1fv(location, count, v);
}

GLvoid StubGLUniform1i(GLint location, GLint x) {
  glUniform1i(location, x);
}

GLvoid StubGLUniform4fv(GLint location, GLsizei count, const GLfloat* v) {
  glUniform4fv(location, count, v);
}

GLvoid StubGLUniformMatrix3fv(GLint location, GLsizei count,
                              GLboolean transpose, const GLfloat* value) {
  glUniformMatrix3fv(location, count, transpose, value);
}

GLboolean StubGLUnmapBuffer(GLenum target) {
  return glUnmapBuffer(target);
}

GLvoid StubGLUseProgram(GLuint program) {
  glUseProgram(program);
}

GLvoid StubGLVertexAttrib4fv(GLuint indx, const GLfloat* values) {
  glVertexAttrib4fv(indx, values);
}

GLvoid StubGLVertexAttribPointer(GLuint indx, GLint size, GLenum type,
                                 GLboolean normalized, GLsizei stride,
                                 const void* ptr) {
  glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
}

GLvoid StubGLViewport(GLint x, GLint y, GLsizei width, GLsizei height) {
  glViewport(x, y, width, height);
}

}  // extern "C"

// Populate |gl_interface| with pointers to the GL implementation used by
// Chrome.
void InitializeGrGLInterface(GrGLInterface* gl_interface) {

  // Propagate the type of GL bindings exported back to skia.
  switch (gfx::GetGLImplementation()) {
    case gfx::kGLImplementationNone:
      NOTREACHED();
      break;
    case gfx::kGLImplementationDesktopGL:
      gl_interface->fBindingsExported = kDesktop_GrGLBinding;
      break;
    case gfx::kGLImplementationOSMesaGL:
      gl_interface->fBindingsExported = kDesktop_GrGLBinding;
      break;
    case gfx::kGLImplementationEGLGLES2:
      gl_interface->fBindingsExported = kES2_GrGLBinding;
      break;
    case gfx::kGLImplementationMockGL:
      NOTREACHED();
      break;
  }

  gl_interface->fClientActiveTexture = NULL;
  gl_interface->fColor4ub = NULL;
  gl_interface->fColorPointer = NULL;
  gl_interface->fDisableClientState = NULL;
  gl_interface->fEnableClientState = NULL;
  gl_interface->fLoadMatrixf = NULL;
  gl_interface->fMatrixMode = NULL;
  gl_interface->fPointSize = NULL;
  gl_interface->fShadeModel = NULL;
  gl_interface->fTexCoordPointer = NULL;
  gl_interface->fTexEnvi = NULL;
  gl_interface->fVertexPointer = NULL;

  gl_interface->fResolveMultisampleFramebuffer = NULL;
  gl_interface->fActiveTexture = StubGLActiveTexture;
  gl_interface->fAttachShader = StubGLAttachShader;
  gl_interface->fBindAttribLocation = StubGLBindAttribLocation;
  gl_interface->fBindBuffer = StubGLBindBuffer;
  gl_interface->fBindTexture = StubGLBindTexture;
  gl_interface->fBlendColor = StubGLBlendColor;
  gl_interface->fBlendFunc = StubGLBlendFunc;
  gl_interface->fBufferData = StubGLBufferData;
  gl_interface->fBufferSubData = StubGLBufferSubData;
  gl_interface->fClear = StubGLClear;
  gl_interface->fClearColor = StubGLClearColor;
  gl_interface->fClearStencil = StubGLClearStencil;
  gl_interface->fColorMask = StubGLColorMask;
  gl_interface->fCompileShader = StubGLCompileShader;
  gl_interface->fCompressedTexImage2D = StubGLCompressedTexImage2D;
  gl_interface->fCreateProgram = StubGLCreateProgram;
  gl_interface->fCreateShader = StubGLCreateShader;
  gl_interface->fCullFace = StubGLCullFace;
  gl_interface->fDeleteBuffers = StubGLDeleteBuffers;
  gl_interface->fDeleteProgram = StubGLDeleteProgram;
  gl_interface->fDeleteShader = StubGLDeleteShader;
  gl_interface->fDeleteTextures = StubGLDeleteTextures;
  gl_interface->fDepthMask = StubGLDepthMask;
  gl_interface->fDisable = StubGLDisable;
  gl_interface->fDisableVertexAttribArray = StubGLDisableVertexAttribArray;
  gl_interface->fDrawArrays = StubGLDrawArrays;
  gl_interface->fDrawElements = StubGLDrawElements;
  gl_interface->fEnable = StubGLEnable;
  gl_interface->fEnableVertexAttribArray = StubGLEnableVertexAttribArray;
  gl_interface->fFrontFace = StubGLFrontFace;
  gl_interface->fGenBuffers = StubGLGenBuffers;
  gl_interface->fGenTextures = StubGLGenTextures;
  gl_interface->fGetBufferParameteriv = StubGLGetBufferParameteriv;
  gl_interface->fGetError = StubGLGetError;
  gl_interface->fGetIntegerv = StubGLGetIntegerv;
  gl_interface->fGetProgramInfoLog = StubGLGetProgramInfoLog;
  gl_interface->fGetProgramiv = StubGLGetProgramiv;
  gl_interface->fGetShaderInfoLog = StubGLGetShaderInfoLog;
  gl_interface->fGetShaderiv = StubGLGetShaderiv;
  gl_interface->fGetString = StubGLGetString;
  gl_interface->fGetUniformLocation = StubGLGetUniformLocation;
  gl_interface->fLineWidth = StubGLLineWidth;
  gl_interface->fLinkProgram = StubGLLinkProgram;
  gl_interface->fPixelStorei = StubGLPixelStorei;
  gl_interface->fReadPixels = StubGLReadPixels;
  gl_interface->fScissor = StubGLScissor;
  gl_interface->fShaderSource = StubGLShaderSource;
  gl_interface->fStencilFunc = StubGLStencilFunc;
  gl_interface->fStencilFuncSeparate = StubGLStencilFuncSeparate;
  gl_interface->fStencilMask = StubGLStencilMask;
  gl_interface->fStencilMaskSeparate = StubGLStencilMaskSeparate;
  gl_interface->fStencilOp = StubGLStencilOp;
  gl_interface->fStencilOpSeparate = StubGLStencilOpSeparate;
  gl_interface->fTexImage2D = StubGLTexImage2D;
  gl_interface->fTexParameteri = StubGLTexParameteri;
  gl_interface->fTexSubImage2D = StubGLTexSubImage2D;
  gl_interface->fUniform1fv = StubGLUniform1fv;
  gl_interface->fUniform1i = StubGLUniform1i;
  gl_interface->fUniform4fv = StubGLUniform4fv;
  gl_interface->fUniformMatrix3fv = StubGLUniformMatrix3fv;
  gl_interface->fUseProgram = StubGLUseProgram;
  gl_interface->fVertexAttrib4fv = StubGLVertexAttrib4fv;
  gl_interface->fVertexAttribPointer = StubGLVertexAttribPointer;
  gl_interface->fViewport = StubGLViewport;
  gl_interface->fBindFramebuffer = StubGLBindFramebuffer;
  gl_interface->fBindRenderbuffer = StubGLBindRenderbuffer;
  gl_interface->fCheckFramebufferStatus = StubGLCheckFramebufferStatus;
  gl_interface->fDeleteFramebuffers = StubGLDeleteFramebuffers;
  gl_interface->fDeleteRenderbuffers = StubGLDeleteRenderbuffers;
  gl_interface->fFramebufferRenderbuffer = StubGLFramebufferRenderbuffer;
  gl_interface->fFramebufferTexture2D = StubGLFramebufferTexture2D;
  gl_interface->fGenFramebuffers = StubGLGenFramebuffers;
  gl_interface->fGenRenderbuffers = StubGLGenRenderbuffers;
  gl_interface->fRenderbufferStorage = StubGLRenderBufferStorage;
  gl_interface->fRenderbufferStorageMultisample =
     StubGLRenderbufferStorageMultisample;
  gl_interface->fBlitFramebuffer = StubGLBlitFramebuffer;
  gl_interface->fMapBuffer = StubGLMapBuffer;
  gl_interface->fUnmapBuffer = StubGLUnmapBuffer;
}

}  // namespace

namespace gfx {

void BindSkiaToHostGL() {
  static GrGLInterface host_gl_interface;
  static bool host_StubGL_initialized = false;
  if (!host_StubGL_initialized) {
    InitializeGrGLInterface(&host_gl_interface);
    GrGLSetGLInterface(&host_gl_interface);
    host_StubGL_initialized = true;
  }
}

}  // namespace gfx