summaryrefslogtreecommitdiffstats
path: root/media/tools/shader_bench/gpu_painter.h
blob: 1fcfb8aa75c1022ab482ff6f4c8765d7d540f061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_TOOLS_SHADER_BENCH_GPU_PAINTER_H_
#define MEDIA_TOOLS_SHADER_BENCH_GPU_PAINTER_H_

#include "media/tools/shader_bench/painter.h"
#include "ui/gfx/gl/gl_bindings.h"
#include "ui/gfx/gl/gl_context.h"
#include "ui/gfx/gl/gl_implementation.h"
#include "ui/gfx/gl/gl_surface.h"

// Class that renders video frames to a window via GPU.
class GPUPainter : public Painter {
 public:
  GPUPainter();
  virtual ~GPUPainter();

  // Returns a reference to the GL context.
  gfx::GLSurface* surface() const { return surface_; }
  gfx::GLContext* context() const { return context_; }

  // Sets context for subsequent gl calls in this painter.
  virtual void SetGLContext(gfx::GLSurface* surface, gfx::GLContext* context);

  // Creates shader program into given context, from the vertex and fragment
  // shader source code. Returns the id of the shader program.
  virtual GLuint CreateShaderProgram(const char* vertex_shader_source,
                                     const char* fragment_shader_source);

 private:
  // Loads shader into given context, from the source code of the
  // shader. type refers to the shader type, either GL_VERTEX_SHADER or
  // GL_FRAGMENT_SHADER. Returns id of shader.
  GLuint LoadShader(unsigned type, const char* shader_source);

  // Reference to the gl context.
  gfx::GLSurface* surface_;
  gfx::GLContext* context_;

  DISALLOW_COPY_AND_ASSIGN(GPUPainter);
};

#endif  // MEDIA_TOOLS_SHADER_BENCH_GPU_PAINTER_H_