summaryrefslogtreecommitdiffstats
path: root/mojo/cc/context_provider_mojo.h
blob: cc465d06837aed9675186a170cec67500d1a97f4 (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
// 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.

#ifndef MOJO_CC_CONTEXT_PROVIDER_MOJO_H_
#define MOJO_CC_CONTEXT_PROVIDER_MOJO_H_

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "cc/output/context_provider.h"
#include "third_party/mojo/src/mojo/public/c/gles2/gles2.h"
#include "third_party/mojo/src/mojo/public/cpp/system/core.h"

namespace mojo {

class ContextProviderMojo : public cc::ContextProvider {
 public:
  explicit ContextProviderMojo(ScopedMessagePipeHandle command_buffer_handle);

  // cc::ContextProvider implementation.
  bool BindToCurrentThread() override;
  gpu::gles2::GLES2Interface* ContextGL() override;
  gpu::ContextSupport* ContextSupport() override;
  class GrContext* GrContext() override;
  void InvalidateGrContext(uint32_t state) override;
  void SetupLock() override;
  base::Lock* GetLock() override;
  Capabilities ContextCapabilities() override;
  void VerifyContexts() override {}
  void DeleteCachedResources() override {}
  bool DestroyedOnMainThread() override;
  void SetLostContextCallback(
      const LostContextCallback& lost_context_callback) override {}
  void SetMemoryPolicyChangedCallback(
      const MemoryPolicyChangedCallback& memory_policy_changed_callback)
      override {}

 protected:
  friend class base::RefCountedThreadSafe<ContextProviderMojo>;
  ~ContextProviderMojo() override;

 private:
  static void ContextLostThunk(void* closure) {
    static_cast<ContextProviderMojo*>(closure)->ContextLost();
  }
  void ContextLost();

  cc::ContextProvider::Capabilities capabilities_;
  ScopedMessagePipeHandle command_buffer_handle_;
  MojoGLES2Context context_;
  scoped_ptr<gpu::gles2::GLES2Interface> context_gl_;

  base::Lock context_lock_;

  DISALLOW_COPY_AND_ASSIGN(ContextProviderMojo);
};

}  // namespace mojo

#endif  // MOJO_CC_CONTEXT_PROVIDER_MOJO_H_