summaryrefslogtreecommitdiffstats
path: root/mojo/cc/context_provider_mojo.cc
blob: 8a759fd468e315c2ddb2ceeff3e413483c992d71 (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
// Copyright 2014 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.

#include "mojo/cc/context_provider_mojo.h"

#include "base/logging.h"

namespace mojo {

ContextProviderMojo::ContextProviderMojo(ScopedMessagePipeHandle gl_pipe)
    : gl_pipe_(gl_pipe.Pass()) {}

bool ContextProviderMojo::BindToCurrentThread() {
  DCHECK(gl_pipe_.is_valid());
  context_ = MojoGLES2CreateContext(
      gl_pipe_.release().value(), &ContextLostThunk, NULL, this);
  return !!context_;
}

gpu::gles2::GLES2Interface* ContextProviderMojo::ContextGL() {
  if (!context_)
    return NULL;
  return static_cast<gpu::gles2::GLES2Interface*>(
      MojoGLES2GetGLES2Interface(context_));
}

gpu::ContextSupport* ContextProviderMojo::ContextSupport() {
  if (!context_)
    return NULL;
  return static_cast<gpu::ContextSupport*>(
      MojoGLES2GetContextSupport(context_));
}

class GrContext* ContextProviderMojo::GrContext() { return NULL; }

cc::ContextProvider::Capabilities ContextProviderMojo::ContextCapabilities() {
  return capabilities_;
}

bool ContextProviderMojo::IsContextLost() { return !context_; }
bool ContextProviderMojo::DestroyedOnMainThread() { return !context_; }

ContextProviderMojo::~ContextProviderMojo() {
  if (context_)
    MojoGLES2DestroyContext(context_);
}

void ContextProviderMojo::ContextLost() {
  if (context_) {
    MojoGLES2DestroyContext(context_);
    context_ = NULL;
  }
}

}  // namespace mojo