Chromium Code Reviews| 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..620c74dddd43e343fba12d1337632cc11e6adbea 100644 |
| --- a/ppapi/tests/power_saver_test_plugin.cc |
| +++ b/ppapi/tests/power_saver_test_plugin.cc |
| @@ -4,6 +4,8 @@ |
| #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" |
| @@ -19,7 +21,9 @@ |
| class PowerSaverTestInstance : public pp::Instance { |
| public: |
| explicit PowerSaverTestInstance(PP_Instance instance) |
| - : pp::Instance(instance), received_first_did_change_view_(false) {} |
| + : pp::Instance(instance), |
| + received_first_did_change_view_(false), |
| + callback_factory_(this) {} |
| ~PowerSaverTestInstance() override {} |
| // For browser tests, responds to: |
| @@ -28,10 +32,12 @@ class PowerSaverTestInstance : public pp::Instance { |
| // peripheral status has changed. |
| void HandleMessage(const pp::Var& message_data) override { |
| if (message_data.is_string()) { |
| - if (message_data.AsString() == "getPeripheralStatus") |
| - BroadcastIsPeripheralStatus("getPeripheralStatusResponse"); |
| + if (message_data.AsString() == "getPowerSaverStatus") |
| + BroadcastStatus("getPowerSaverStatusResponse"); |
| else if (message_data.AsString() == "peripheralStatusChange") |
| - BroadcastIsPeripheralStatus("peripheralStatusChange"); |
| + BroadcastStatus("peripheralStatusChange"); |
| + else if (message_data.AsString() == "throttleStatusChange") |
| + BroadcastStatus("throttleStatusChange"); |
| } |
| } |
| @@ -39,22 +45,57 @@ class PowerSaverTestInstance : public pp::Instance { |
| // tests that await initial plugin creation. |
| void DidChangeView(const pp::View& view) override { |
| if (!received_first_did_change_view_) { |
| - BroadcastIsPeripheralStatus("initial"); |
| + BroadcastStatus("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) { |
| + void Paint() { |
|
tommycli
2015/04/28 18:43:16
The test plugin provides a striped image to the th
|
| + 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)); |
| + } |
| + |
| + void BroadcastStatus(const std::string& source) { |
| pp::VarDictionary message; |
| message.Set( |
| "isPeripheral", |
| pp::Var(PP_ToBool(GetTestingInterface()->IsPeripheral(pp_instance())))); |
| + message.Set( |
| + "isThrottled", |
| + pp::Var(PP_ToBool(GetTestingInterface()->IsThrottled(pp_instance())))); |
| message.Set("source", pp::Var(source)); |
| PostMessage(message); |
| } |
| bool received_first_did_change_view_; |
| + pp::View view_; |
| + pp::Graphics2D device_context_; |
| + |
| + pp::CompletionCallbackFactory<PowerSaverTestInstance> callback_factory_; |
| }; |
| class PowerSaverTestModule : public pp::Module { |