Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.cc
bloba1070c337b0dcf67fdd277cb3d2b064b08a31aef
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 #if (ANGLE_SH_VERSION >= 126)
32 sh::GLenum shader_type,
33 #else
34 ShShaderType shader_type,
35 #endif
36 ShShaderSpec shader_spec,
37 const ShBuiltInResources* resources,
38 ShaderTranslatorInterface::GlslImplementationType
39 glsl_implementation_type,
40 ShCompileOptions driver_bug_workarounds) {
41 ShaderTranslatorInitParams params(shader_type,
42 shader_spec,
43 *resources,
44 glsl_implementation_type,
45 driver_bug_workarounds);
47 Cache::iterator it = cache_.find(params);
48 if (it != cache_.end())
49 return it->second;
51 ShaderTranslator* translator = new ShaderTranslator();
52 if (translator->Init(shader_type, shader_spec, resources,
53 glsl_implementation_type,
54 driver_bug_workarounds)) {
55 cache_[params] = translator;
56 translator->AddDestructionObserver(this);
57 return translator;
58 } else {
59 return NULL;
63 } // namespace gles2
64 } // namespace gpu