Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: ppapi/tests/power_saver_test_plugin.cc

Issue 1182283002: Plugin Power Saver: Fix Dr. Memory leaks in browser tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ppapi/examples/gamepad/gamepad.cc ('k') | tools/valgrind/drmemory/suppressions_full.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <algorithm> 5 #include <algorithm>
6 6
7 #include "ppapi/cpp/graphics_2d.h" 7 #include "ppapi/cpp/graphics_2d.h"
8 #include "ppapi/cpp/image_data.h" 8 #include "ppapi/cpp/image_data.h"
9 #include "ppapi/cpp/instance.h" 9 #include "ppapi/cpp/instance.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
11 #include "ppapi/tests/test_utils.h" 11 #include "ppapi/tests/test_utils.h"
12 12
13 // Windows defines 'PostMessage', so we have to undef it. 13 // Windows defines 'PostMessage', so we have to undef it.
14 #ifdef PostMessage 14 #ifdef PostMessage
15 #undef PostMessage 15 #undef PostMessage
16 #endif 16 #endif
17 17
18 static void DummyCompletionCallback(void*, int32_t) {
19 }
20
18 // This is a simple C++ Pepper plugin that enables Plugin Power Saver tests. 21 // This is a simple C++ Pepper plugin that enables Plugin Power Saver tests.
19 class PowerSaverTestInstance : public pp::Instance { 22 class PowerSaverTestInstance : public pp::Instance {
20 public: 23 public:
21 explicit PowerSaverTestInstance(PP_Instance instance) 24 explicit PowerSaverTestInstance(PP_Instance instance)
22 : pp::Instance(instance), callback_factory_(this) {} 25 : pp::Instance(instance) {}
23 ~PowerSaverTestInstance() override {} 26 ~PowerSaverTestInstance() override {}
24 27
25 bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 28 bool Init(uint32_t argc, const char* argn[], const char* argv[]) {
26 GetTestingInterface()->SubscribeToPowerSaverNotifications(pp_instance()); 29 GetTestingInterface()->SubscribeToPowerSaverNotifications(pp_instance());
27 return true; 30 return true;
28 } 31 }
29 32
30 void HandleMessage(const pp::Var& message_data) override { 33 void HandleMessage(const pp::Var& message_data) override {
31 if (message_data.is_string() && 34 if (message_data.is_string() &&
32 message_data.AsString() == "getPowerSaverStatus") { 35 message_data.AsString() == "getPowerSaverStatus") {
33 GetTestingInterface()->PostPowerSaverStatus(pp_instance()); 36 GetTestingInterface()->PostPowerSaverStatus(pp_instance());
34 } 37 }
35 } 38 }
36 39
37 // Broadcast our peripheral status after the initial view data. This is for 40 // Broadcast our peripheral status after the initial view data. This is for
38 // tests that await initial plugin creation. 41 // tests that await initial plugin creation.
39 void DidChangeView(const pp::View& view) override { 42 void DidChangeView(const pp::View& view) override {
40 view_ = view; 43 view_ = view;
41 device_context_ = pp::Graphics2D(this, view_.GetRect().size(), true); 44 device_context_ = pp::Graphics2D(this, view_.GetRect().size(), true);
42 if (!BindGraphics(device_context_)) 45 if (!BindGraphics(device_context_))
43 return; 46 return;
44 47
48 // Since we draw a static image, we only need to make a new frame when
49 // the device is initialized or the view size changes.
45 Paint(); 50 Paint();
46 } 51 }
47 52
48 void OnFlush(int32_t) { Paint(); }
49
50 private: 53 private:
51 void Paint() { 54 void Paint() {
52 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL, 55 pp::ImageData image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
53 view_.GetRect().size(), true); 56 view_.GetRect().size(), true);
54 if (image.is_null()) 57 if (image.is_null())
55 return; 58 return;
56 59
57 // Draw black and white stripes to present an "interesting" keyframe. 60 // Draw black and white stripes to present an "interesting" keyframe.
58 for (int y = 0; y < view_.GetRect().size().height(); ++y) { 61 for (int y = 0; y < view_.GetRect().size().height(); ++y) {
59 for (int x = 0; x < view_.GetRect().size().width(); ++x) { 62 for (int x = 0; x < view_.GetRect().size().width(); ++x) {
60 uint32_t color = x % 2 ? 0xFF0000FF : 0xFFFFFFFF; 63 uint32_t color = x % 2 ? 0xFF0000FF : 0xFFFFFFFF;
61 *image.GetAddr32(pp::Point(x, y)) = color; 64 *image.GetAddr32(pp::Point(x, y)) = color;
62 } 65 }
63 } 66 }
64 67
65 device_context_.ReplaceContents(&image); 68 device_context_.ReplaceContents(&image);
66 device_context_.Flush( 69 device_context_.Flush(
67 callback_factory_.NewCallback(&PowerSaverTestInstance::OnFlush)); 70 pp::CompletionCallback(&DummyCompletionCallback, nullptr));
68 } 71 }
69 72
70 pp::View view_; 73 pp::View view_;
71 pp::Graphics2D device_context_; 74 pp::Graphics2D device_context_;
72
73 pp::CompletionCallbackFactory<PowerSaverTestInstance> callback_factory_;
74 }; 75 };
75 76
76 class PowerSaverTestModule : public pp::Module { 77 class PowerSaverTestModule : public pp::Module {
77 public: 78 public:
78 PowerSaverTestModule() : pp::Module() {} 79 PowerSaverTestModule() : pp::Module() {}
79 virtual ~PowerSaverTestModule() {} 80 virtual ~PowerSaverTestModule() {}
80 81
81 virtual pp::Instance* CreateInstance(PP_Instance instance) { 82 virtual pp::Instance* CreateInstance(PP_Instance instance) {
82 return new PowerSaverTestInstance(instance); 83 return new PowerSaverTestInstance(instance);
83 } 84 }
84 }; 85 };
85 86
86 namespace pp { 87 namespace pp {
87 88
88 Module* CreateModule() { 89 Module* CreateModule() {
89 return new PowerSaverTestModule(); 90 return new PowerSaverTestModule();
90 } 91 }
91 92
92 } // namespace pp 93 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/examples/gamepad/gamepad.cc ('k') | tools/valgrind/drmemory/suppressions_full.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698