Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / ppapi / tests / power_saver_test_plugin.cc
blob44aef4d9577b5f41f02d2111beed28b4d9fc4068
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <algorithm>
7 #include "ppapi/cpp/graphics_2d.h"
8 #include "ppapi/cpp/image_data.h"
9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h"
11 #include "ppapi/tests/test_utils.h"
13 // Windows defines 'PostMessage', so we have to undef it.
14 #ifdef PostMessage
15 #undef PostMessage
16 #endif
18 // This is a simple C++ Pepper plugin that enables Plugin Power Saver tests.
19 class PowerSaverTestInstance : public pp::Instance {
20 public:
21 explicit PowerSaverTestInstance(PP_Instance instance)
22 : pp::Instance(instance), callback_factory_(this) {}
23 ~PowerSaverTestInstance() override {}
25 bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
26 GetTestingInterface()->SubscribeToPowerSaverNotifications(pp_instance());
27 return true;
30 void HandleMessage(const pp::Var& message_data) override {
31 if (message_data.is_string() &&
32 message_data.AsString() == "getPowerSaverStatus") {
33 GetTestingInterface()->PostPowerSaverStatus(pp_instance());
37 // Broadcast our peripheral status after the initial view data. This is for
38 // tests that await initial plugin creation.
39 void DidChangeView(const pp::View& view) override {
40 view_ = view;
41 device_context_ = pp::Graphics2D(this, view_.GetRect().size(), true);
42 if (!BindGraphics(device_context_))
43 return;
45 Paint();
48 void OnFlush(int32_t) { Paint(); }
50 private:
51 void Paint() {
52 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
53 view_.GetRect().size(), true);
54 if (image.is_null())
55 return;
57 // Draw black and white stripes to present an "interesting" keyframe.
58 for (int y = 0; y < view_.GetRect().size().height(); ++y) {
59 for (int x = 0; x < view_.GetRect().size().width(); ++x) {
60 uint32_t color = x % 2 ? 0xFF0000FF : 0xFFFFFFFF;
61 *image.GetAddr32(pp::Point(x, y)) = color;
65 device_context_.ReplaceContents(&image);
66 device_context_.Flush(
67 callback_factory_.NewCallback(&PowerSaverTestInstance::OnFlush));
70 pp::View view_;
71 pp::Graphics2D device_context_;
73 pp::CompletionCallbackFactory<PowerSaverTestInstance> callback_factory_;
76 class PowerSaverTestModule : public pp::Module {
77 public:
78 PowerSaverTestModule() : pp::Module() {}
79 virtual ~PowerSaverTestModule() {}
81 virtual pp::Instance* CreateInstance(PP_Instance instance) {
82 return new PowerSaverTestInstance(instance);
86 namespace pp {
88 Module* CreateModule() {
89 return new PowerSaverTestModule();
92 } // namespace pp