Make GL bindings conditional
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.cc
blob631a88e4142128ad200f827832a720950af20f8f
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
3 // found in the LICENSE file.
5 #include <GLES2/gl2.h>
7 #include "gpu/command_buffer/service/shader_translator_cache.h"
9 namespace gpu {
10 namespace gles2 {
12 ShaderTranslatorCache::ShaderTranslatorCache() {
15 ShaderTranslatorCache::~ShaderTranslatorCache() {
16 DCHECK(cache_.empty());
19 void ShaderTranslatorCache::OnDestruct(ShaderTranslator* translator) {
20 Cache::iterator it = cache_.begin();
21 while (it != cache_.end()) {
22 if (it->second == translator) {
23 cache_.erase(it);
24 return;
26 it++;
30 scoped_refptr<ShaderTranslator> ShaderTranslatorCache::GetTranslator(
31 sh::GLenum shader_type,
32 ShShaderSpec shader_spec,
33 const ShBuiltInResources* resources,
34 ShaderTranslatorInterface::GlslImplementationType
35 glsl_implementation_type,
36 ShCompileOptions driver_bug_workarounds) {
37 ShaderTranslatorInitParams params(shader_type,
38 shader_spec,
39 *resources,
40 glsl_implementation_type,
41 driver_bug_workarounds);
43 Cache::iterator it = cache_.find(params);
44 if (it != cache_.end())
45 return it->second;
47 ShaderTranslator* translator = new ShaderTranslator();
48 if (translator->Init(shader_type, shader_spec, resources,
49 glsl_implementation_type,
50 driver_bug_workarounds)) {
51 cache_[params] = translator;
52 translator->AddDestructionObserver(this);
53 return translator;
54 } else {
55 return NULL;
59 } // namespace gles2
60 } // namespace gpu