Infobar material design refresh: bg color
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.cc
blobf78039fcac25d72c900bc2360ceb668fe669abb2
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 <GLES2/gl2.h>
7 #include "gpu/command_buffer/service/shader_translator_cache.h"
9 namespace gpu {
10 namespace gles2 {
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) {
23 cache_.erase(it);
24 return;
26 it++;
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())
42 return it->second;
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);
49 return translator;
50 } else {
51 return NULL;
55 } // namespace gles2
56 } // namespace gpu