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

Unified Diff: mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.cc

Issue 178953003: Mojo container example for hosting Pepper plugins (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 6 years, 9 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
Index: mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.cc
diff --git a/mojo/examples/sample_app/spinning_cube.cc b/mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.cc
similarity index 87%
copy from mojo/examples/sample_app/spinning_cube.cc
copy to mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.cc
index 7983563fd60ebf55eeb415aceefb1b89e7a28e50..223351038f491a5bbe39529ab87b05e12cfe5ecd 100644
--- a/mojo/examples/sample_app/spinning_cube.cc
+++ b/mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.cc
@@ -1,4 +1,4 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright 2014 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.
@@ -14,13 +14,15 @@
// http://www.opengles-book.com
//
-#include "mojo/examples/sample_app/spinning_cube.h"
+#include "mojo/examples/pepper_container_app/pepper_spinning_cube_demo/spinning_cube.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
+
+#include <algorithm>
+
+#include "ppapi/lib/gl/include/GLES2/gl2.h"
namespace mojo {
namespace examples {
@@ -353,41 +355,47 @@ SpinningCube::~SpinningCube() {
glDeleteBuffers(1, &state_->vbo_indices_);
if (state_->program_object_)
glDeleteProgram(state_->program_object_);
+
+ delete state_;
}
void SpinningCube::Init(uint32_t width, uint32_t height) {
width_ = width;
height_ = height;
- const char vertext_shader_source[] =
- "uniform mat4 u_mvpMatrix; \n"
- "attribute vec4 a_position; \n"
- "void main() \n"
- "{ \n"
- " gl_Position = u_mvpMatrix * a_position; \n"
- "} \n";
-
- const char fragment_shader_source[] =
- "precision mediump float; \n"
- "void main() \n"
- "{ \n"
- " gl_FragColor = vec4( 0.0, 1.0, 0.0, 1.0 ); \n"
- "} \n";
-
- state_->program_object_ = LoadProgram(
- vertext_shader_source, fragment_shader_source);
- state_->position_location_ = glGetAttribLocation(
- state_->program_object_, "a_position");
- state_->mvp_location_ = glGetUniformLocation(
- state_->program_object_, "u_mvpMatrix");
- state_->num_indices_ = GenerateCube(
- &state_->vbo_vertices_, &state_->vbo_indices_);
-
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- initialized_ = true;
+ if (!initialized_) {
+ initialized_ = true;
+ const char vertext_shader_source[] =
+ "uniform mat4 u_mvpMatrix; \n"
+ "attribute vec4 a_position; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = u_mvpMatrix * a_position; \n"
+ "} \n";
+
+ const char fragment_shader_source[] =
+ "precision mediump float; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_FragColor = vec4( 0.0, 0.0, 1.0, 1.0 ); \n"
+ "} \n";
+
+ state_->program_object_ = LoadProgram(
+ vertext_shader_source, fragment_shader_source);
+ state_->position_location_ = glGetAttribLocation(
+ state_->program_object_, "a_position");
+ state_->mvp_location_ = glGetUniformLocation(
+ state_->program_object_, "u_mvpMatrix");
+ state_->num_indices_ = GenerateCube(
+ &state_->vbo_vertices_, &state_->vbo_indices_);
+
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
+ }
}
void SpinningCube::OnGLContextLost() {
+ // TODO(yzshen): Is it correct that in this case we don't need to do cleanup
+ // for program and buffers?
initialized_ = false;
height_ = 0;
width_ = 0;

Powered by Google App Engine
This is Rietveld 408576698