summaryrefslogtreecommitdiffstats
path: root/cc/test/fake_context_provider.cc
blob: ed777fc0af8a172c2885b4654977e8876c2fce6d (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.

#include "cc/test/fake_context_provider.h"

#include "cc/test/test_web_graphics_context_3d.h"

namespace cc {

FakeContextProvider::FakeContextProvider()
    : destroyed_(false) {
}

FakeContextProvider::FakeContextProvider(
    const CreateCallback& create_callback)
    : create_callback_(create_callback),
      destroyed_(false) {
}

FakeContextProvider::~FakeContextProvider() {}

bool FakeContextProvider::InitializeOnMainThread() {
  if (destroyed_)
    return false;
  if (context3d_)
    return true;

  if (create_callback_.is_null())
    context3d_ = TestWebGraphicsContext3D::Create().Pass();
  else
    context3d_ = create_callback_.Run();
  destroyed_ = !context3d_;
  return !!context3d_;
}

bool FakeContextProvider::BindToCurrentThread() {
  return context3d_->makeContextCurrent();
}

WebKit::WebGraphicsContext3D* FakeContextProvider::Context3d() {
  return context3d_.get();
}
class GrContext* FakeContextProvider::GrContext() {
  // TODO(danakj): Make a fake GrContext.
  return NULL;
}

void FakeContextProvider::VerifyContexts() {
  if (!Context3d() || Context3d()->isContextLost()) {
    base::AutoLock lock(destroyed_lock_);
    destroyed_ = true;
  }
}

bool FakeContextProvider::DestroyedOnMainThread() {
  base::AutoLock lock(destroyed_lock_);
  return destroyed_;
}

}  // namespace cc