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 #if (ANGLE_SH_VERSION >= 126)
32 sh::GLenum shader_type
,
34 ShShaderType shader_type
,
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
,
44 glsl_implementation_type
,
45 driver_bug_workarounds
);
47 Cache::iterator it
= cache_
.find(params
);
48 if (it
!= cache_
.end())
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);