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 ShShaderOutput shader_output_language
,
35 ShCompileOptions driver_bug_workarounds
) {
36 ShaderTranslatorInitParams
params(shader_type
, shader_spec
, *resources
,
37 shader_output_language
,
38 driver_bug_workarounds
);
40 Cache::iterator it
= cache_
.find(params
);
41 if (it
!= cache_
.end())
44 ShaderTranslator
* translator
= new ShaderTranslator();
45 if (translator
->Init(shader_type
, shader_spec
, resources
,
46 shader_output_language
, driver_bug_workarounds
)) {
47 cache_
[params
] = translator
;
48 translator
->AddDestructionObserver(this);