Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / gpu / command_buffer / service / program_cache.h
blob624c436016f7c834f235bfe21093618884d316bc
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_PROGRAM_CACHE_H_
6 #define GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_
8 #include <map>
9 #include <string>
11 #include "base/containers/hash_tables.h"
12 #include "base/sha1.h"
13 #include "gpu/command_buffer/common/gles2_cmd_format.h"
14 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
15 #include "gpu/command_buffer/service/shader_manager.h"
17 namespace gpu {
18 namespace gles2 {
20 class Shader;
22 // Program cache base class for caching linked gpu programs
23 class GPU_EXPORT ProgramCache {
24 public:
25 static const size_t kHashLength = base::kSHA1Length;
27 typedef std::map<std::string, GLint> LocationMap;
29 enum LinkedProgramStatus {
30 LINK_UNKNOWN,
31 LINK_SUCCEEDED
34 enum ProgramLoadResult {
35 PROGRAM_LOAD_FAILURE,
36 PROGRAM_LOAD_SUCCESS
39 ProgramCache();
40 virtual ~ProgramCache();
42 LinkedProgramStatus GetLinkedProgramStatus(
43 const std::string& shader_signature_a,
44 const std::string& shader_signature_b,
45 const LocationMap* bind_attrib_location_map) const;
47 // Loads the linked program from the cache. If the program is not found or
48 // there was an error, PROGRAM_LOAD_FAILURE should be returned.
49 virtual ProgramLoadResult LoadLinkedProgram(
50 GLuint program,
51 Shader* shader_a,
52 Shader* shader_b,
53 const LocationMap* bind_attrib_location_map,
54 const ShaderCacheCallback& shader_callback) = 0;
56 // Saves the program into the cache. If successful, the implementation should
57 // call LinkedProgramCacheSuccess.
58 virtual void SaveLinkedProgram(
59 GLuint program,
60 const Shader* shader_a,
61 const Shader* shader_b,
62 const LocationMap* bind_attrib_location_map,
63 const ShaderCacheCallback& shader_callback) = 0;
65 virtual void LoadProgram(const std::string& program) = 0;
67 // clears the cache
68 void Clear();
70 // Only for testing
71 void LinkedProgramCacheSuccess(const std::string& shader_signature_a,
72 const std::string& shader_signature_b,
73 const LocationMap* bind_attrib_location_map);
75 protected:
76 // called by implementing class after a shader was successfully cached
77 void LinkedProgramCacheSuccess(const std::string& program_hash);
79 // result is not null terminated
80 void ComputeShaderHash(const std::string& shader,
81 char* result) const;
83 // result is not null terminated. hashed shaders are expected to be
84 // kHashLength in length
85 void ComputeProgramHash(
86 const char* hashed_shader_0,
87 const char* hashed_shader_1,
88 const LocationMap* bind_attrib_location_map,
89 char* result) const;
91 void Evict(const std::string& program_hash);
93 private:
94 typedef base::hash_map<std::string,
95 LinkedProgramStatus> LinkStatusMap;
97 // called to clear the backend cache
98 virtual void ClearBackend() = 0;
100 LinkStatusMap link_status_;
102 DISALLOW_COPY_AND_ASSIGN(ProgramCache);
105 } // namespace gles2
106 } // namespace gpu
108 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_