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 "gpu/command_buffer/service/shader_translator_cache.h"
10 ShaderTranslatorCache* ShaderTranslatorCache::GetInstance() {
11 return Singleton<ShaderTranslatorCache>::get();
14 ShaderTranslatorCache::ShaderTranslatorCache() {
17 ShaderTranslatorCache::~ShaderTranslatorCache() {
20 void ShaderTranslatorCache::OnDestruct(ShaderTranslator* translator) {
21 Cache::iterator it = cache_.begin();
22 while (it != cache_.end()) {
23 if (it->second == translator) {
31 scoped_refptr<ShaderTranslator> ShaderTranslatorCache::GetTranslator(
32 ShShaderType shader_type,
33 ShShaderSpec shader_spec,
34 const ShBuiltInResources* resources,
35 ShaderTranslatorInterface::GlslImplementationType
36 glsl_implementation_type,
37 ShCompileOptions driver_bug_workarounds) {
38 ShaderTranslatorInitParams params(shader_type,
41 glsl_implementation_type,
42 driver_bug_workarounds);
44 Cache::iterator it = cache_.find(params);
45 if (it != cache_.end())
48 ShaderTranslator* translator = new ShaderTranslator();
49 if (translator->Init(shader_type, shader_spec, resources,
50 glsl_implementation_type,
51 driver_bug_workarounds)) {
52 cache_[params] = translator;
53 translator->AddDestructionObserver(this);