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

Side by Side Diff: ui/cc/ProgramBinding.cpp

Issue 10701016: Initial import attempt, just to play with. Many things disabled/removed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/cc/ProgramBinding.h ('k') | ui/cc/RateLimiter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #if USE(ACCELERATED_COMPOSITING)
29
30 #include "ProgramBinding.h"
31
32 #include "GeometryBinding.h"
33 #include "GraphicsContext3D.h"
34 #include "LayerRendererChromium.h"
35 #include "TraceEvent.h"
36 #include <public/WebGraphicsContext3D.h>
37 #include <wtf/text/CString.h>
38
39 using WebKit::WebGraphicsContext3D;
40
41 namespace WebCore {
42
43 ProgramBindingBase::ProgramBindingBase()
44 : m_program(0)
45 , m_initialized(false)
46 {
47 }
48
49 ProgramBindingBase::~ProgramBindingBase()
50 {
51 // If you hit these asserts, you initialized but forgot to call cleanup().
52 ASSERT(!m_program);
53 ASSERT(!m_initialized);
54 }
55
56 static bool contextLost(WebGraphicsContext3D* context)
57 {
58 return (context->getGraphicsResetStatusARB() != GL_NO_ERROR);
59 }
60
61
62 void ProgramBindingBase::init(WebGraphicsContext3D* context, const String& verte xShader, const String& fragmentShader)
63 {
64 m_program = createShaderProgram(context, vertexShader, fragmentShader);
65 ASSERT(m_program || contextLost(context));
66 }
67
68 void ProgramBindingBase::cleanup(WebGraphicsContext3D* context)
69 {
70 m_initialized = false;
71 if (!m_program)
72 return;
73
74 ASSERT(context);
75 GLC(context, context->deleteProgram(m_program));
76 m_program = 0;
77 }
78
79 unsigned ProgramBindingBase::loadShader(WebGraphicsContext3D* context, unsigned type, const String& shaderSource)
80 {
81 unsigned shader = context->createShader(type);
82 if (!shader)
83 return 0;
84 String sourceString(shaderSource);
85 GLC(context, context->shaderSource(shader, sourceString.utf8().data()));
86 GLC(context, context->compileShader(shader));
87 #ifndef NDEBUG
88 int compiled = 0;
89 GLC(context, context->getShaderiv(shader, GL_COMPILE_STATUS, &compiled));
90 if (!compiled) {
91 GLC(context, context->deleteShader(shader));
92 return 0;
93 }
94 #endif
95 return shader;
96 }
97
98 unsigned ProgramBindingBase::createShaderProgram(WebGraphicsContext3D* context, const String& vertexShaderSource, const String& fragmentShaderSource)
99 {
100 TRACE_EVENT0("cc", "ProgramBindingBase::createShaderProgram");
101 unsigned vertexShader = loadShader(context, GL_VERTEX_SHADER, vertexShaderSo urce);
102 if (!vertexShader) {
103 if (!contextLost(context))
104 LOG_ERROR("Failed to create vertex shader");
105 return 0;
106 }
107
108 unsigned fragmentShader = loadShader(context, GL_FRAGMENT_SHADER, fragmentSh aderSource);
109 if (!fragmentShader) {
110 GLC(context, context->deleteShader(vertexShader));
111 if (!contextLost(context))
112 LOG_ERROR("Failed to create fragment shader");
113 return 0;
114 }
115
116 unsigned programObject = context->createProgram();
117 if (!programObject) {
118 if (!contextLost(context))
119 LOG_ERROR("Failed to create shader program");
120 return 0;
121 }
122
123 GLC(context, context->attachShader(programObject, vertexShader));
124 GLC(context, context->attachShader(programObject, fragmentShader));
125
126 // Bind the common attrib locations.
127 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::pos itionAttribLocation(), "a_position"));
128 GLC(context, context->bindAttribLocation(programObject, GeometryBinding::tex CoordAttribLocation(), "a_texCoord"));
129
130 GLC(context, context->linkProgram(programObject));
131 #ifndef NDEBUG
132 int linked = 0;
133 GLC(context, context->getProgramiv(programObject, GL_LINK_STATUS, &linked));
134 if (!linked) {
135 if (!contextLost(context))
136 LOG_ERROR("Failed to link shader program");
137 GLC(context, context->deleteProgram(programObject));
138 return 0;
139 }
140 #endif
141
142 GLC(context, context->deleteShader(vertexShader));
143 GLC(context, context->deleteShader(fragmentShader));
144 return programObject;
145 }
146
147 } // namespace WebCore
148
149 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW
« no previous file with comments | « ui/cc/ProgramBinding.h ('k') | ui/cc/RateLimiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698