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.
7 #include "gpu/command_buffer/service/shader_translator_cache.h"
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
) {
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
,
40 glsl_implementation_type
,
41 driver_bug_workarounds
);
43 Cache::iterator it
= cache_
.find(params
);
44 if (it
!= cache_
.end())
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);