Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / gpu / command_buffer / service / shader_translator_cache.h
blob6b0b1a57ef35cfc3a727a8962db1af05803dbae3
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 #ifndef GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_
8 #include <string.h>
10 #include <map>
12 #include "base/memory/ref_counted.h"
13 #include "gpu/command_buffer/service/shader_translator.h"
14 #include "third_party/angle/include/GLSLANG/ShaderLang.h"
16 namespace gpu {
17 namespace gles2 {
19 // This class is not thread safe and can only be created and destroyed
20 // on a single thread. But it is safe to use two independent instances on two
21 // threads without synchronization.
23 // TODO(backer): Investigate using glReleaseShaderCompiler as an alternative to
24 // to this cache.
25 class GPU_EXPORT ShaderTranslatorCache
26 : public base::RefCounted<ShaderTranslatorCache>,
27 public NON_EXPORTED_BASE(ShaderTranslator::DestructionObserver) {
28 public:
29 ShaderTranslatorCache();
31 // ShaderTranslator::DestructionObserver implementation
32 void OnDestruct(ShaderTranslator* translator) override;
34 scoped_refptr<ShaderTranslator> GetTranslator(
35 sh::GLenum shader_type,
36 ShShaderSpec shader_spec,
37 const ShBuiltInResources* resources,
38 ShaderTranslatorInterface::GlslImplementationType
39 glsl_implementation_type,
40 ShCompileOptions driver_bug_workarounds);
42 private:
43 friend class base::RefCounted<ShaderTranslatorCache>;
44 friend class ShaderTranslatorCacheTest_InitParamComparable_Test;
45 ~ShaderTranslatorCache() override;
47 // Parameters passed into ShaderTranslator::Init
48 struct ShaderTranslatorInitParams {
49 sh::GLenum shader_type;
50 ShShaderSpec shader_spec;
51 ShBuiltInResources resources;
52 ShaderTranslatorInterface::GlslImplementationType
53 glsl_implementation_type;
54 ShCompileOptions driver_bug_workarounds;
56 ShaderTranslatorInitParams(sh::GLenum shader_type,
57 ShShaderSpec shader_spec,
58 const ShBuiltInResources& resources,
59 ShaderTranslatorInterface::GlslImplementationType
60 glsl_implementation_type,
61 ShCompileOptions driver_bug_workarounds) {
62 memset(this, 0, sizeof(*this));
63 this->shader_type = shader_type;
64 this->shader_spec = shader_spec;
65 this->resources = resources;
66 this->glsl_implementation_type = glsl_implementation_type;
67 this->driver_bug_workarounds = driver_bug_workarounds;
70 ShaderTranslatorInitParams(const ShaderTranslatorInitParams& params) {
71 memcpy(this, &params, sizeof(*this));
74 bool operator== (const ShaderTranslatorInitParams& params) const {
75 return memcmp(&params, this, sizeof(*this)) == 0;
78 bool operator< (const ShaderTranslatorInitParams& params) const {
79 return memcmp(&params, this, sizeof(*this)) < 0;
82 private:
83 ShaderTranslatorInitParams();
84 ShaderTranslatorInitParams& operator=(const ShaderTranslatorInitParams&);
87 typedef std::map<ShaderTranslatorInitParams, ShaderTranslator* > Cache;
88 Cache cache_;
90 DISALLOW_COPY_AND_ASSIGN(ShaderTranslatorCache);
93 } // namespace gles2
94 } // namespace gpu
96 #endif // GPU_COMMAND_BUFFER_SERVICE_SHADER_TRANSLATOR_CACHE_H_