summaryrefslogtreecommitdiffstats
path: root/app/gfx/gl/gl_context_egl.h
blob: 9c598254fee1fc12c753c068fc578110f7a6dba4 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2010 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 APP_GFX_GL_GL_CONTEXT_EGL_H_
#define APP_GFX_GL_GL_CONTEXT_EGL_H_
#pragma once

#include "gfx/size.h"
#include "app/gfx/gl/gl_context.h"

typedef void* EGLDisplay;
typedef void* EGLContext;
typedef void* EGLSurface;

namespace gfx {

// Interface for EGL contexts. Adds an EGL specific accessor for retreiving
// the surface.
class BaseEGLContext : public GLContext {
 public:
  BaseEGLContext() {}
  virtual ~BaseEGLContext() {}

  // Implement GLContext.
  virtual EGLSurface GetSurface() = 0;

  static bool InitializeOneOff();

  static EGLDisplay GetDisplay();

 private:
  DISALLOW_COPY_AND_ASSIGN(BaseEGLContext);
};

// Encapsulates an EGL OpenGL ES context that renders to a view.
class NativeViewEGLContext : public BaseEGLContext {
 public:
  explicit NativeViewEGLContext(void* window);
  virtual ~NativeViewEGLContext();

  // Initialize an EGL context.
  bool Initialize();

  // Implement GLContext.
  virtual void Destroy();
  virtual bool MakeCurrent();
  virtual bool IsCurrent();
  virtual bool IsOffscreen();
  virtual void SwapBuffers();
  virtual gfx::Size GetSize();
  virtual void* GetHandle();

  // Implement BaseEGLContext.
  virtual EGLSurface GetSurface();

 private:
  void* window_;
  EGLSurface surface_;
  EGLContext context_;

  DISALLOW_COPY_AND_ASSIGN(NativeViewEGLContext);
};

// Encapsulates an EGL OpenGL ES context intended for offscreen use. It is
// actually associated with a native window and will render to it. The caller
// must bind an FBO to prevent this. Not using pbuffers because ANGLE does not
// support them.
class SecondaryEGLContext : public BaseEGLContext {
 public:
  SecondaryEGLContext();
  virtual ~SecondaryEGLContext();

  // Initialize an EGL context that shares a namespace with another.
  bool Initialize(GLContext* shared_context);

  // Implement GLContext.
  virtual void Destroy();
  virtual bool MakeCurrent();
  virtual bool IsCurrent();
  virtual bool IsOffscreen();
  virtual void SwapBuffers();
  virtual gfx::Size GetSize();
  virtual void* GetHandle();

  // Implement BaseEGLContext.
  virtual EGLSurface GetSurface();

 private:
  // All offscreen
  EGLSurface surface_;
  bool own_surface_;
  EGLContext context_;

  DISALLOW_COPY_AND_ASSIGN(SecondaryEGLContext);
};

}  // namespace gfx

#endif  // APP_GFX_GL_GL_CONTEXT_EGL_H_