Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Unified Diff: examples/spinning_cube/gles2_client_impl.cc

Issue 940293003: Add a Display and ContextProvider concept to mojom, use to recreate (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/spinning_cube/gles2_client_impl.h ('k') | examples/spinning_cube/spinning_cube.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/spinning_cube/gles2_client_impl.cc
diff --git a/examples/spinning_cube/gles2_client_impl.cc b/examples/spinning_cube/gles2_client_impl.cc
index 3c7f0455911214004ca9e39722b58960e0c760f5..9ea7e5e5606a4db6d1984ae0651202b587e3a873 100644
--- a/examples/spinning_cube/gles2_client_impl.cc
+++ b/examples/spinning_cube/gles2_client_impl.cc
@@ -28,14 +28,15 @@ float GetRandomColor() {
}
-GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer)
- : last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) {
- context_ =
- MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(),
- &ContextLostThunk,
- this,
- mojo::Environment::GetDefaultAsyncWaiter());
- MojoGLES2MakeCurrent(context_);
+GLES2ClientImpl::GLES2ClientImpl(mojo::ContextProviderPtr context_provider)
+ : last_time_(mojo::GetTimeTicksNow()),
+ waiting_to_draw_(false),
+ context_provider_(context_provider.Pass()),
+ context_(nullptr) {
+ context_provider_->Create(nullptr,
+ [this](mojo::CommandBufferPtr command_buffer) {
+ ContextCreated(command_buffer.Pass());
+ });
}
GLES2ClientImpl::~GLES2ClientImpl() {
@@ -44,13 +45,13 @@ GLES2ClientImpl::~GLES2ClientImpl() {
void GLES2ClientImpl::SetSize(const mojo::Size& size) {
size_ = size;
- if (size_.width == 0 || size_.height == 0)
+ cube_.set_size(size_.width, size_.height);
+ if (size_.width == 0 || size_.height == 0 || !context_)
return;
static_cast<gpu::gles2::GLES2Interface*>(
MojoGLES2GetGLES2Interface(context_))->ResizeCHROMIUM(size_.width,
size_.height,
1);
- cube_.Init(size_.width, size_.height);
WantToDraw();
}
@@ -100,32 +101,41 @@ void GLES2ClientImpl::HandleInputEvent(const mojo::Event& event) {
}
}
+void GLES2ClientImpl::ContextCreated(mojo::CommandBufferPtr command_buffer) {
+ context_ = MojoGLES2CreateContext(
+ command_buffer.PassMessagePipe().release().value(), &ContextLostThunk,
+ this, mojo::Environment::GetDefaultAsyncWaiter());
+ MojoGLES2MakeCurrent(context_);
+ cube_.Init();
+ WantToDraw();
+}
+
void GLES2ClientImpl::ContextLost() {
+ cube_.OnGLContextLost();
+ MojoGLES2DestroyContext(context_);
+ context_ = nullptr;
+ context_provider_->Create(nullptr,
+ [this](mojo::CommandBufferPtr command_buffer) {
+ ContextCreated(command_buffer.Pass());
+ });
}
void GLES2ClientImpl::ContextLostThunk(void* closure) {
static_cast<GLES2ClientImpl*>(closure)->ContextLost();
}
-struct DrawRunnable {
- explicit DrawRunnable(GLES2ClientImpl* impl) : impl(impl) {}
- virtual ~DrawRunnable() {}
-
- void Run() const { impl->Draw(); }
-
- GLES2ClientImpl* impl;
-};
-
void GLES2ClientImpl::WantToDraw() {
- if (waiting_to_draw_)
+ if (waiting_to_draw_ || !context_)
return;
waiting_to_draw_ = true;
- mojo::RunLoop::current()->PostDelayedTask(mojo::Closure(DrawRunnable(this)),
+ mojo::RunLoop::current()->PostDelayedTask([this]() { Draw(); },
MojoTimeTicks(16667));
}
void GLES2ClientImpl::Draw() {
waiting_to_draw_ = false;
+ if (!context_)
+ return;
MojoTimeTicks now = mojo::GetTimeTicksNow();
MojoTimeTicks offset = now - last_time_;
float delta = static_cast<float>(offset) / 1000000.;
« no previous file with comments | « examples/spinning_cube/gles2_client_impl.h ('k') | examples/spinning_cube/spinning_cube.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698