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() {
13 ShaderTranslatorCache::~ShaderTranslatorCache() {
14 DCHECK(cache_
.empty());
17 void ShaderTranslatorCache::OnDestruct(ShaderTranslator
* translator
) {
18 Cache::iterator it
= cache_
.begin();
19 while (it
!= cache_
.end()) {
20 if (it
->second
== translator
) {
28 scoped_refptr
<ShaderTranslator
> ShaderTranslatorCache::GetTranslator(
29 ShShaderType shader_type
,
30 ShShaderSpec shader_spec
,
31 const ShBuiltInResources
* resources
,
32 ShaderTranslatorInterface::GlslImplementationType
33 glsl_implementation_type
,
34 ShCompileOptions driver_bug_workarounds
) {
35 ShaderTranslatorInitParams
params(shader_type
,
38 glsl_implementation_type
,
39 driver_bug_workarounds
);
41 Cache::iterator it
= cache_
.find(params
);
42 if (it
!= cache_
.end())
45 ShaderTranslator
* translator
= new ShaderTranslator();
46 if (translator
->Init(shader_type
, shader_spec
, resources
,
47 glsl_implementation_type
,
48 driver_bug_workarounds
)) {
49 cache_
[params
] = translator
;
50 translator
->AddDestructionObserver(this);