Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: src/gpu/gl/builders/GrGLShaderStringBuilder.cpp

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrGLShaderStringBuilder.h"
9 #include "../GrGpuGL.h"
10 #include "gl/GrGLSLPrettyPrint.h"
11 #include "SkRTConf.h"
12 #include "SkTraceEvent.h"
13
14 #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X)
15 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X)
16
17 SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false,
18 "Print the source code for all shaders generated.");
19
20 namespace GrGLShaderStringBuilder {
21 GrGLuint attachShader(const GrGLContext& glCtx,
22 GrGLuint programId,
23 GrGLenum type,
24 const SkString& shaderSrc) {
25 const GrGLInterface* gli = glCtx.interface();
26
27 GrGLuint shaderId;
28 GR_GL_CALL_RET(gli, shaderId, CreateShader(type));
29 if (0 == shaderId) {
30 return 0;
31 }
32
33 #ifdef SK_DEBUG
34 SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, false );
35 const GrGLchar* sourceStr = prettySource.c_str();
36 GrGLint sourceLength = static_cast<GrGLint>(prettySource.size());
37 #else
38 GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size());
39 const GrGLchar* sourceStr = shaderSrc.c_str();
40 #endif
41 GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
42 GR_GL_CALL(gli, CompileShader(shaderId));
43
44 // Calling GetShaderiv in Chromium is quite expensive. Assume success in re lease builds.
45 bool checkCompiled = !glCtx.isChromium();
46 #ifdef SK_DEBUG
47 checkCompiled = true;
48 #endif
49 if (checkCompiled) {
50 GrGLint compiled = GR_GL_INIT_ZERO;
51 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled)) ;
52
53 if (!compiled) {
54 GrGLint infoLen = GR_GL_INIT_ZERO;
55 GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoL en));
56 SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debug ger
57 if (infoLen > 0) {
58 // retrieve length even though we don't need it to workaround b ug in Chromium cmd
59 // buffer param validation.
60 GrGLsizei length = GR_GL_INIT_ZERO;
61 GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1,
62 &length, (char*)log.get()));
63 GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_ str());
64 GrPrintf("\n%s", log.get());
65 }
66 SkDEBUGFAIL("Shader compilation failed!");
67 GR_GL_CALL(gli, DeleteShader(shaderId));
68 return 0;
69 }
70 }
71
72 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::GLSh ader",
73 TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY(sha derSrc.c_str()));
74 if (c_PrintShaders) {
75 GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str());
76 GrPrintf("\n");
77 }
78
79 // Attach the shader, but defer deletion until after we have linked the pro gram.
80 // This works around a bug in the Android emulator's GLES2 wrapper which
81 // will immediately delete the shader object and free its memory even thoug h it's
82 // attached to a program, which then causes glLinkProgram to fail.
83 GR_GL_CALL(gli, AttachShader(programId, shaderId));
84
85 return shaderId;
86 }
87 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698