source: trunk/src/platform/nacl/opengl_context.cpp @ 2506

Last change on this file since 2506 was 2506, checked in by sam, 7 years ago

base: start removing occurrences of NULL on our long journey to nullptr.

  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1// Copyright (c) 2011 The Native Client 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.
4
5#if defined HAVE_CONFIG_H
6#   include "config.h"
7#endif
8
9#include <pthread.h>
10#include <ppapi/cpp/completion_callback.h>
11#include <ppapi/gles2/gl2ext_ppapi.h>
12
13#include "core.h"
14
15#include "platform/nacl/opengl_context.h"
16
17namespace {
18// This is called by the brower when the 3D context has been flushed to the
19// browser window.
20void FlushCallback(void* data, int32_t result) {
21  static_cast<lol::OpenGLContext*>(data)->set_flush_pending(false);
22}
23}  // namespace
24
25namespace lol {
26
27OpenGLContext::OpenGLContext(pp::Instance* instance)
28    : pp::Graphics3DClient(instance),
29      flush_pending_(false) {
30  pp::Module* module = pp::Module::Get();
31  assert(module);
32  gles2_interface_ = static_cast<const struct PPB_OpenGLES2*>(
33      module->GetBrowserInterface(PPB_OPENGLES2_INTERFACE));
34  assert(gles2_interface_);
35}
36
37OpenGLContext::~OpenGLContext() {
38  glSetCurrentContextPPAPI(0);
39}
40
41bool OpenGLContext::MakeContextCurrent(pp::Instance* instance)
42{
43  if (instance == nullptr)
44  {
45    glSetCurrentContextPPAPI(0);
46    return false;
47  }
48  // Lazily create the Pepper context.
49  if (context_.is_null()) {
50    int32_t attribs[] = {
51        PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
52        PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 24,
53        PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 8,
54        PP_GRAPHICS3DATTRIB_SAMPLES, 0,
55        PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
56        PP_GRAPHICS3DATTRIB_WIDTH, size_.width(),
57        PP_GRAPHICS3DATTRIB_HEIGHT, size_.height(),
58        PP_GRAPHICS3DATTRIB_NONE
59    };
60    context_ = pp::Graphics3D(instance, pp::Graphics3D(), attribs);
61    if (context_.is_null()) {
62      glSetCurrentContextPPAPI(0);
63      return false;
64    }
65    instance->BindGraphics(context_);
66  }
67  glSetCurrentContextPPAPI(context_.pp_resource());
68  return true;
69}
70
71void OpenGLContext::InvalidateContext(pp::Instance* instance) {
72  glSetCurrentContextPPAPI(0);
73}
74
75void OpenGLContext::ResizeContext(const pp::Size& size) {
76  size_ = size;
77  if (!context_.is_null()) {
78    context_.ResizeBuffers(size.width(), size.height());
79  }
80}
81
82
83void OpenGLContext::FlushContext() {
84  if (flush_pending()) {
85    // A flush is pending so do nothing; just drop this flush on the floor.
86    return;
87  }
88  set_flush_pending(true);
89  context_.SwapBuffers(pp::CompletionCallback(&FlushCallback, this));
90}
91}  // namespace lol
92
Note: See TracBrowser for help on using the repository browser.