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

Side by Side Diff: gpu/command_buffer/service/shader_translator.cc

Issue 10694111: RefCounted types should not have public destructors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix android & Win compiles 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 | « gpu/command_buffer/service/shader_translator.h ('k') | ipc/ipc_listener.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/shader_translator.h" 5 #include "gpu/command_buffer/service/shader_translator.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace { 13 namespace {
14
15 using gpu::gles2::ShaderTranslator;
16
14 void FinalizeShaderTranslator(void* /* dummy */) { 17 void FinalizeShaderTranslator(void* /* dummy */) {
15 ShFinalize(); 18 ShFinalize();
16 } 19 }
17 20
18 bool InitializeShaderTranslator() { 21 bool InitializeShaderTranslator() {
19 static bool initialized = false; 22 static bool initialized = false;
20 if (!initialized && ShInitialize()) { 23 if (!initialized && ShInitialize()) {
21 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL); 24 base::AtExitManager::RegisterCallback(&FinalizeShaderTranslator, NULL);
22 initialized = true; 25 initialized = true;
23 } 26 }
24 return initialized; 27 return initialized;
25 } 28 }
26 29
27 using gpu::gles2::ShaderTranslator;
28 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type, 30 void GetVariableInfo(ShHandle compiler, ShShaderInfo var_type,
29 ShaderTranslator::VariableMap* var_map) { 31 ShaderTranslator::VariableMap* var_map) {
30 int name_len = 0, mapped_name_len = 0; 32 int name_len = 0, mapped_name_len = 0;
31 switch (var_type) { 33 switch (var_type) {
32 case SH_ACTIVE_ATTRIBUTES: 34 case SH_ACTIVE_ATTRIBUTES:
33 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len); 35 ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &name_len);
34 break; 36 break;
35 case SH_ACTIVE_UNIFORMS: 37 case SH_ACTIVE_UNIFORMS:
36 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len); 38 ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &name_len);
37 break; 39 break;
(...skipping 27 matching lines...) Expand all
65 // to handle long struct field name mapping before we can do this. 67 // to handle long struct field name mapping before we can do this.
66 // Also, we should modify the ANGLE interface to also return a length 68 // Also, we should modify the ANGLE interface to also return a length
67 // for mapped_name. 69 // for mapped_name.
68 std::string name_string(name.get(), std::min(len, name_len - 1)); 70 std::string name_string(name.get(), std::min(len, name_len - 1));
69 mapped_name.get()[mapped_name_len - 1] = '\0'; 71 mapped_name.get()[mapped_name_len - 1] = '\0';
70 72
71 ShaderTranslator::VariableInfo info(type, size, name_string); 73 ShaderTranslator::VariableInfo info(type, size, name_string);
72 (*var_map)[mapped_name.get()] = info; 74 (*var_map)[mapped_name.get()] = info;
73 } 75 }
74 } 76 }
77
75 } // namespace 78 } // namespace
76 79
77 namespace gpu { 80 namespace gpu {
78 namespace gles2 { 81 namespace gles2 {
79 82
80 ShaderTranslator::DestructionObserver::DestructionObserver() { 83 ShaderTranslator::DestructionObserver::DestructionObserver() {
81 } 84 }
82 85
83 ShaderTranslator::DestructionObserver::~DestructionObserver() { 86 ShaderTranslator::DestructionObserver::~DestructionObserver() {
84 } 87 }
85 88
86 ShaderTranslator::ShaderTranslator() 89 ShaderTranslator::ShaderTranslator()
87 : compiler_(NULL), 90 : compiler_(NULL),
88 implementation_is_glsl_es_(false), 91 implementation_is_glsl_es_(false),
89 needs_built_in_function_emulation_(false) { 92 needs_built_in_function_emulation_(false) {
90 } 93 }
91 94
92 ShaderTranslator::~ShaderTranslator() {
93 FOR_EACH_OBSERVER(DestructionObserver,
94 destruction_observers_,
95 OnDestruct(this));
96
97 if (compiler_ != NULL)
98 ShDestruct(compiler_);
99 }
100
101 bool ShaderTranslator::Init( 95 bool ShaderTranslator::Init(
102 ShShaderType shader_type, 96 ShShaderType shader_type,
103 ShShaderSpec shader_spec, 97 ShShaderSpec shader_spec,
104 const ShBuiltInResources* resources, 98 const ShBuiltInResources* resources,
105 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type, 99 ShaderTranslatorInterface::GlslImplementationType glsl_implementation_type,
106 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior 100 ShaderTranslatorInterface::GlslBuiltInFunctionBehavior
107 glsl_built_in_function_behavior) { 101 glsl_built_in_function_behavior) {
108 // Make sure Init is called only once. 102 // Make sure Init is called only once.
109 DCHECK(compiler_ == NULL); 103 DCHECK(compiler_ == NULL);
110 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER); 104 DCHECK(shader_type == SH_FRAGMENT_SHADER || shader_type == SH_VERTEX_SHADER);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 void ShaderTranslator::AddDestructionObserver( 178 void ShaderTranslator::AddDestructionObserver(
185 DestructionObserver* observer) { 179 DestructionObserver* observer) {
186 destruction_observers_.AddObserver(observer); 180 destruction_observers_.AddObserver(observer);
187 } 181 }
188 182
189 void ShaderTranslator::RemoveDestructionObserver( 183 void ShaderTranslator::RemoveDestructionObserver(
190 DestructionObserver* observer) { 184 DestructionObserver* observer) {
191 destruction_observers_.RemoveObserver(observer); 185 destruction_observers_.RemoveObserver(observer);
192 } 186 }
193 187
188 ShaderTranslator::~ShaderTranslator() {
189 FOR_EACH_OBSERVER(DestructionObserver,
190 destruction_observers_,
191 OnDestruct(this));
192
193 if (compiler_ != NULL)
194 ShDestruct(compiler_);
195 }
196
194 void ShaderTranslator::ClearResults() { 197 void ShaderTranslator::ClearResults() {
195 translated_shader_.reset(); 198 translated_shader_.reset();
196 info_log_.reset(); 199 info_log_.reset();
197 attrib_map_.clear(); 200 attrib_map_.clear();
198 uniform_map_.clear(); 201 uniform_map_.clear();
199 } 202 }
200 203
201 } // namespace gles2 204 } // namespace gles2
202 } // namespace gpu 205 } // namespace gpu
203 206
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/shader_translator.h ('k') | ipc/ipc_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698