Index: ppapi/tests/power_saver_test_plugin.cc |
diff --git a/ppapi/tests/power_saver_test_plugin.cc b/ppapi/tests/power_saver_test_plugin.cc |
index f14c5fe5a807fc9c6867879b370ba1e08bbe3ff6..44aef4d9577b5f41f02d2111beed28b4d9fc4068 100644 |
--- a/ppapi/tests/power_saver_test_plugin.cc |
+++ b/ppapi/tests/power_saver_test_plugin.cc |
@@ -4,10 +4,10 @@ |
#include <algorithm> |
+#include "ppapi/cpp/graphics_2d.h" |
+#include "ppapi/cpp/image_data.h" |
#include "ppapi/cpp/instance.h" |
#include "ppapi/cpp/module.h" |
-#include "ppapi/cpp/var.h" |
-#include "ppapi/cpp/var_dictionary.h" |
#include "ppapi/tests/test_utils.h" |
// Windows defines 'PostMessage', so we have to undef it. |
@@ -19,42 +19,58 @@ |
class PowerSaverTestInstance : public pp::Instance { |
public: |
explicit PowerSaverTestInstance(PP_Instance instance) |
- : pp::Instance(instance), received_first_did_change_view_(false) {} |
+ : pp::Instance(instance), callback_factory_(this) {} |
~PowerSaverTestInstance() override {} |
- // For browser tests, responds to: |
- // - When postMessage("isPeripheral") is called on the plugin DOM element. |
- // - When the plugin throttler posts a message notifying us that our |
- // peripheral status has changed. |
+ bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
+ GetTestingInterface()->SubscribeToPowerSaverNotifications(pp_instance()); |
+ return true; |
+ } |
+ |
void HandleMessage(const pp::Var& message_data) override { |
- if (message_data.is_string()) { |
- if (message_data.AsString() == "getPeripheralStatus") |
- BroadcastIsPeripheralStatus("getPeripheralStatusResponse"); |
- else if (message_data.AsString() == "peripheralStatusChange") |
- BroadcastIsPeripheralStatus("peripheralStatusChange"); |
+ if (message_data.is_string() && |
+ message_data.AsString() == "getPowerSaverStatus") { |
+ GetTestingInterface()->PostPowerSaverStatus(pp_instance()); |
} |
} |
// Broadcast our peripheral status after the initial view data. This is for |
// tests that await initial plugin creation. |
void DidChangeView(const pp::View& view) override { |
- if (!received_first_did_change_view_) { |
- BroadcastIsPeripheralStatus("initial"); |
- received_first_did_change_view_ = true; |
- } |
+ view_ = view; |
+ device_context_ = pp::Graphics2D(this, view_.GetRect().size(), true); |
+ if (!BindGraphics(device_context_)) |
+ return; |
+ |
+ Paint(); |
} |
+ void OnFlush(int32_t) { Paint(); } |
+ |
private: |
- void BroadcastIsPeripheralStatus(const std::string& source) { |
- pp::VarDictionary message; |
- message.Set( |
- "isPeripheral", |
- pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); |
- message.Set("source", pp::Var(source)); |
- PostMessage(message); |
+ void Paint() { |
+ pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
+ view_.GetRect().size(), true); |
+ if (image.is_null()) |
+ return; |
+ |
+ // Draw black and white stripes to present an "interesting" keyframe. |
+ for (int y = 0; y < view_.GetRect().size().height(); ++y) { |
+ for (int x = 0; x < view_.GetRect().size().width(); ++x) { |
+ uint32_t color = x % 2 ? 0xFF0000FF : 0xFFFFFFFF; |
+ *image.GetAddr32(pp::Point(x, y)) = color; |
+ } |
+ } |
+ |
+ device_context_.ReplaceContents(&image); |
+ device_context_.Flush( |
+ callback_factory_.NewCallback(&PowerSaverTestInstance::OnFlush)); |
} |
- bool received_first_did_change_view_; |
+ pp::View view_; |
+ pp::Graphics2D device_context_; |
+ |
+ pp::CompletionCallbackFactory<PowerSaverTestInstance> callback_factory_; |
}; |
class PowerSaverTestModule : public pp::Module { |