summaryrefslogtreecommitdiffstats
path: root/ppapi/examples
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 20:21:13 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-04 20:21:13 +0000
commit204f1df524af03fa30c20b9d57c4c89ce0162b42 (patch)
treef0831574bacacd626ea124ec01cd2cd0e922a4e1 /ppapi/examples
parent8f104af0562fd65b427ebbb08cd98ad0caa14f5c (diff)
downloadchromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.zip
chromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.tar.gz
chromium_src-204f1df524af03fa30c20b9d57c4c89ce0162b42.tar.bz2
Hook up page visibility to the View info for a plugin.
TEST=manual (run audio example and switch tab visibility) BUG= Review URL: http://codereview.chromium.org/9022016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116370 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/examples')
-rw-r--r--ppapi/examples/audio/audio.cc16
1 files changed, 14 insertions, 2 deletions
diff --git a/ppapi/examples/audio/audio.cc b/ppapi/examples/audio/audio.cc
index ca7ff88..2c01faf 100644
--- a/ppapi/examples/audio/audio.cc
+++ b/ppapi/examples/audio/audio.cc
@@ -19,6 +19,7 @@
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
+#include "ppapi/cpp/view.h"
// Separate left and right frequency to make sure we didn't swap L & R.
// Sounds pretty horrible, though...
@@ -35,6 +36,7 @@ class MyInstance : public pp::Instance {
public:
explicit MyInstance(PP_Instance instance)
: pp::Instance(instance),
+ visible_(false),
sample_rate_(kDefaultSampleRate),
sample_count_(0),
audio_wave_l_(0.0),
@@ -60,6 +62,12 @@ class MyInstance : public pp::Instance {
return audio_.StartPlayback();
}
+ virtual void DidChangeView(const pp::View& view) {
+ // The frequency will change depending on whether the page is in the
+ // foreground or background.
+ visible_ = view.IsPageVisible();
+ }
+
private:
static void SineWaveCallbackTrampoline(void* samples,
uint32_t num_bytes,
@@ -68,8 +76,10 @@ class MyInstance : public pp::Instance {
}
void SineWaveCallback(void* samples, uint32_t num_bytes) {
- double delta_l = 2.0 * M_PI * kLeftFrequency / sample_rate_;
- double delta_r = 2.0 * M_PI * kRightFrequency / sample_rate_;
+ double delta_l = 2.0 * M_PI * kLeftFrequency / sample_rate_ /
+ (visible_ ? 1 : 2);
+ double delta_r = 2.0 * M_PI * kRightFrequency / sample_rate_ /
+ (visible_ ? 1 : 2);
// Use per channel audio wave value to avoid clicks on buffer boundries.
double wave_l = audio_wave_l_;
@@ -92,6 +102,8 @@ class MyInstance : public pp::Instance {
audio_wave_r_ = wave_r;
}
+ bool visible_;
+
PP_AudioSampleRate sample_rate_;
uint32_t sample_count_;