blob: 2a87ca0acf9a4fff309cf7b6cc0c7ac26fd82cfb (
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
|
// 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 "mojo/examples/sample_app/gles2_client_impl.h"
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "mojo/public/gles2/gles2.h"
namespace mojo {
namespace examples {
GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe)
: service_(pipe.Pass()) {
service_.SetPeer(this);
}
GLES2ClientImpl::~GLES2ClientImpl() {
service_->Destroy();
}
void GLES2ClientImpl::DidCreateContext(uint64_t encoded,
uint32_t width,
uint32_t height) {
MojoGLES2MakeCurrent(encoded);
cube_.Init(width, height);
last_time_ = base::Time::Now();
timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16),
this, &GLES2ClientImpl::Draw);
}
void GLES2ClientImpl::Draw() {
base::Time now = base::Time::Now();
base::TimeDelta offset = now - last_time_;
last_time_ = now;
cube_.Update(offset.InSecondsF());
cube_.Draw();
MojoGLES2SwapBuffers();
}
void GLES2ClientImpl::ContextLost() {
timer_.Stop();
}
} // namespace examples
} // namespace mojo
|