summaryrefslogtreecommitdiffstats
path: root/ppapi/examples
diff options
context:
space:
mode:
authorpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 17:00:46 +0000
committerpenghuang@chromium.org <penghuang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-20 17:00:46 +0000
commit83649fbe67e5f083e9bbfa5276e85c3cd1817a3f (patch)
tree1346d656858ac0a6fe44093301d6a6514f1f1a32 /ppapi/examples
parentaaf6cce59e126b77ad17f2e8452c83ae56e0111f (diff)
downloadchromium_src-83649fbe67e5f083e9bbfa5276e85c3cd1817a3f.zip
chromium_src-83649fbe67e5f083e9bbfa5276e85c3cd1817a3f.tar.gz
chromium_src-83649fbe67e5f083e9bbfa5276e85c3cd1817a3f.tar.bz2
[PPAPI] Add browser tests for compositor API
And fix a bug found with the tests. BindGraphics() does not work for a device which is in the same type with the current bound device. BUG=374383 R=piman@chromium.org, raymes@chromium.org Review URL: https://codereview.chromium.org/324983005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278728 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples')
-rw-r--r--ppapi/examples/compositor/compositor.cc52
1 files changed, 29 insertions, 23 deletions
diff --git a/ppapi/examples/compositor/compositor.cc b/ppapi/examples/compositor/compositor.cc
index 360bfba..e7e3f1f 100644
--- a/ppapi/examples/compositor/compositor.cc
+++ b/ppapi/examples/compositor/compositor.cc
@@ -72,6 +72,7 @@ class DemoInstance : public pp::Instance, public pp::Graphics3DClient {
void InitGL(int32_t result);
GLuint PrepareFramebuffer();
pp::ImageData PrepareImage();
+ void PrepareLayers(int32_t frame);
void Paint(int32_t result, int32_t frame);
void OnTextureReleased(int32_t result, GLuint texture);
void OnImageReleased(int32_t result, const pp::ImageData& image);
@@ -106,8 +107,7 @@ DemoInstance::DemoInstance(PP_Instance instance)
context_(NULL),
fbo_(0),
rbo_(0),
- compositor_(this),
- rebuild_layers_(false),
+ rebuild_layers_(true),
total_resource_(0),
cube_(new SpinningCube()) {
RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE);
@@ -147,11 +147,7 @@ bool DemoInstance::HandleInputEvent(const pp::InputEvent& event) {
void DemoInstance::Graphics3DContextLost() {
fbo_ = 0;
rbo_ = 0;
- compositor_.ResetLayers();
- color_layer_ = pp::CompositorLayer();
- stable_texture_layer_ = pp::CompositorLayer();
- texture_layer_ = pp::CompositorLayer();
- image_layer_ = pp::CompositorLayer();
+ rebuild_layers_ = true;
total_resource_ -= static_cast<int32_t>(textures_.size());
textures_.clear();
delete context_;
@@ -260,14 +256,12 @@ pp::ImageData DemoInstance::PrepareImage() {
void DemoInstance::Paint(int32_t result, int32_t frame) {
assert(result == PP_OK);
-
if (result != PP_OK || !context_)
return;
- int32_t rv;
-
if (rebuild_layers_) {
- compositor_.ResetLayers();
+ compositor_ = pp::Compositor(this);
+ assert(BindGraphics(compositor_));
color_layer_ = pp::CompositorLayer();
stable_texture_layer_ = pp::CompositorLayer();
texture_layer_ = pp::CompositorLayer();
@@ -276,6 +270,21 @@ void DemoInstance::Paint(int32_t result, int32_t frame) {
rebuild_layers_ = false;
}
+ PrepareLayers(frame);
+
+ int32_t rv = compositor_.CommitLayers(
+ callback_factory_.NewCallback(&DemoInstance::Paint, ++frame));
+ assert(rv == PP_OK_COMPLETIONPENDING);
+
+ pp::VarDictionary dict;
+ dict.Set("total_resource", total_resource_);
+ size_t free_resource = textures_.size() + images_.size();
+ dict.Set("free_resource", static_cast<int32_t>(free_resource));
+ PostMessage(dict);
+}
+
+void DemoInstance::PrepareLayers(int32_t frame) {
+ int32_t rv;
float factor_sin = sin(M_PI / 180 * frame);
float factor_cos = cos(M_PI / 180 * frame);
{
@@ -395,26 +404,23 @@ void DemoInstance::Paint(int32_t result, int32_t frame) {
rv = texture_layer_.SetPremultipliedAlpha(PP_FALSE);
assert(rv == PP_OK);
}
-
- rv = compositor_.CommitLayers(
- callback_factory_.NewCallback(&DemoInstance::Paint, ++frame));
- assert(rv == PP_OK_COMPLETIONPENDING);
-
- pp::VarDictionary dict;
- dict.Set(pp::Var("total_resource"), pp::Var(total_resource_));
- dict.Set(pp::Var("free_resource"),
- pp::Var((int32_t)(textures_.size() + images_.size())));
- PostMessage(dict);
}
void DemoInstance::OnTextureReleased(int32_t result, GLuint texture) {
- if (result == PP_OK)
+ if (result == PP_OK) {
textures_.push_back(texture);
+ } else {
+ glDeleteTextures(1, &texture);
+ total_resource_--;
+ }
}
void DemoInstance::OnImageReleased(int32_t result, const pp::ImageData& image) {
- if (result == PP_OK)
+ if (result == PP_OK) {
images_.push_back(image);
+ } else {
+ total_resource_--;
+ }
}
// This object is the global object representing this plugin library as long