Performance histograms for extension content verification
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.cc
blobf204186c7e70b86576bf4118693fc39f1b7bda3b
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"
7 namespace gpu {
8 namespace gles2 {
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) {
21 cache_.erase(it);
22 return;
24 it++;
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,
36 shader_spec,
37 *resources,
38 glsl_implementation_type,
39 driver_bug_workarounds);
41 Cache::iterator it = cache_.find(params);
42 if (it != cache_.end())
43 return it->second;
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);
51 return translator;
52 } else {
53 return NULL;
57 } // namespace gles2
58 } // namespace gpu