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_
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"
22 // Program cache base class for caching linked gpu programs
23 class GPU_EXPORT ProgramCache
{
25 static const size_t kHashLength
= base::kSHA1Length
;
27 typedef std::map
<std::string
, GLint
> LocationMap
;
29 enum LinkedProgramStatus
{
34 enum ProgramLoadResult
{
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(
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(
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;
71 void LinkedProgramCacheSuccess(const std::string
& shader_signature_a
,
72 const std::string
& shader_signature_b
,
73 const LocationMap
* bind_attrib_location_map
);
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
,
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
,
91 void Evict(const std::string
& program_hash
);
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
);
108 #endif // GPU_COMMAND_BUFFER_SERVICE_PROGRAM_CACHE_H_