summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_context_provider.h
blob: 9ab1abd3d383619cf35b3c157db36a3cffc88112 (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 2013 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 CC_TEST_FAKE_CONTEXT_PROVIDER_H_
#define CC_TEST_FAKE_CONTEXT_PROVIDER_H_

#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/synchronization/lock.h"
#include "cc/output/context_provider.h"

namespace cc {
class TestWebGraphicsContext3D;

class FakeContextProvider : public cc::ContextProvider {
 public:
  typedef base::Callback<scoped_ptr<TestWebGraphicsContext3D>(void)>
    CreateCallback;

  static scoped_refptr<FakeContextProvider> Create() {
    scoped_refptr<FakeContextProvider> provider = new FakeContextProvider();
    if (!provider->InitializeOnMainThread())
      return NULL;
    return provider;
  }

  static scoped_refptr<FakeContextProvider> Create(
      const CreateCallback& create_callback) {
    scoped_refptr<FakeContextProvider> provider =
        new FakeContextProvider(create_callback);
    if (!provider->InitializeOnMainThread())
      return NULL;
    return provider;
  }

  virtual bool BindToCurrentThread() OVERRIDE;
  virtual WebKit::WebGraphicsContext3D* Context3d() OVERRIDE;
  virtual class GrContext* GrContext() OVERRIDE;
  virtual void VerifyContexts() OVERRIDE;
  virtual bool DestroyedOnMainThread() OVERRIDE;

 protected:
  FakeContextProvider();
  explicit FakeContextProvider(const CreateCallback& create_callback);
  virtual ~FakeContextProvider();

  bool InitializeOnMainThread();

  CreateCallback create_callback_;
  scoped_ptr<WebKit::WebGraphicsContext3D> context3d_;
  bool bound_;

  base::Lock destroyed_lock_;
  bool destroyed_;
};

}  // namespace cc

#endif  // CC_TEST_FAKE_CONTEXT_PROVIDER_H_