context_provider_in_process.h revision fb250657ef40d7500f20882d5c9909c1013367d3
1// Copyright (c) 2013 The Chromium 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#ifndef WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
6#define WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
7
8#include "base/compiler_specific.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/synchronization/lock.h"
11#include "base/threading/thread_checker.h"
12#include "cc/output/context_provider.h"
13#include "webkit/common/gpu/webkit_gpu_export.h"
14
15namespace WebKit {
16class WebGraphicsContext3D;
17}
18
19namespace webkit {
20namespace gpu {
21class GrContextForWebGraphicsContext3D;
22
23class WEBKIT_GPU_EXPORT ContextProviderInProcess
24    : NON_EXPORTED_BASE(public cc::ContextProvider) {
25 public:
26  static scoped_refptr<ContextProviderInProcess> Create() {
27    scoped_refptr<ContextProviderInProcess> provider =
28        new ContextProviderInProcess;
29    if (!provider->InitializeOnMainThread())
30      return NULL;
31    return provider;
32  }
33
34  virtual bool BindToCurrentThread() OVERRIDE;
35  virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
36  virtual class GrContext* GrContext() OVERRIDE;
37  virtual void VerifyContexts() OVERRIDE;
38  virtual bool DestroyedOnMainThread() OVERRIDE;
39  virtual void SetLostContextCallback(
40      const LostContextCallback& lost_context_callback) OVERRIDE;
41
42 protected:
43  ContextProviderInProcess();
44  virtual ~ContextProviderInProcess();
45
46  bool InitializeOnMainThread();
47
48  void OnLostContext();
49  void OnMemoryAllocationChanged(bool nonzero_allocation);
50
51 private:
52  base::ThreadChecker main_thread_checker_;
53  base::ThreadChecker context_thread_checker_;
54
55  scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
56  scoped_ptr<webkit::gpu::GrContextForWebGraphicsContext3D> gr_context_;
57
58  LostContextCallback lost_context_callback_;
59
60  base::Lock destroyed_lock_;
61  bool destroyed_;
62
63  class LostContextCallbackProxy;
64  scoped_ptr<LostContextCallbackProxy> lost_context_callback_proxy_;
65
66  class MemoryAllocationCallbackProxy;
67  scoped_ptr<MemoryAllocationCallbackProxy> memory_allocation_callback_proxy_;
68};
69
70}  // namespace gpu
71}  // namespace webkit
72
73#endif  // WEBKIT_COMMON_GPU_CONTEXT_PROVIDER_IN_PROCESS_H_
74