1 // Copyright (c) 2013 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 CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_SHADER_PROGRAMS_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_SHADER_PROGRAMS_MAC_H_
10 #include "base/basictypes.h"
14 // Provides caching of the compile-and-link step for shader programs at runtime
15 // since, once compiled and linked, the programs can be shared. Callers invoke
16 // one of the UseXXX() methods within a GL context to glUseProgram() the program
17 // and have its uniform variables bound with the given parameters.
18 class CompositingIOSurfaceShaderPrograms
{
20 CompositingIOSurfaceShaderPrograms();
21 ~CompositingIOSurfaceShaderPrograms();
23 // Reset the cache, deleting any references to currently-cached shader
24 // programs. This must be called within an active OpenGL context just before
28 // Begin using the "blit" program, which is set up to sample the texture at
29 // GL_TEXTURE_0. Returns false on error.
30 bool UseBlitProgram();
32 // Begin using the program that just draws solid white very efficiently.
33 // Returns false on error.
34 bool UseSolidWhiteProgram();
36 // Begin using one of the two RGB-to-YV12 color conversion programs, as
37 // specified by |pass_number| 1 or 2. The programs will sample the texture at
38 // GL_TEXTURE0, and account for scaling in the X direction by |texel_scale_x|.
39 // Returns false on error.
40 bool UseRGBToYV12Program(int pass_number
, float texel_scale_x
);
43 enum { kNumShaderPrograms
= 4 };
45 // Helper methods to cache uniform variable locations.
46 GLuint
GetShaderProgram(int which
);
47 void BindUniformTextureVariable(int which
, int texture_unit_offset
);
48 void BindUniformTexelScaleXVariable(int which
, float texel_scale_x
);
50 // Cached values for previously-compiled/linked shader programs, and the
51 // locations of their uniform variables.
52 GLuint shader_programs_
[kNumShaderPrograms
];
53 GLint texture_var_locations_
[kNumShaderPrograms
];
54 GLint texel_scale_x_var_locations_
[kNumShaderPrograms
];
56 DISALLOW_COPY_AND_ASSIGN(CompositingIOSurfaceShaderPrograms
);
59 } // namespace content
61 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_SHADER_PROGRAMS_MAC_H_