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

Side by Side Diff: ppapi/examples/input/touch_drawing_plugin.cc

Issue 300413002: Add simple pepper plugin telemetry test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
dmichael (off chromium) 2014/05/29 16:28:04 I think it's preferred to leave off the "(c)". Als
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
dmichael (off chromium) 2014/05/29 16:28:04 This file doesn't seem to belong in ppapi/examples
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 I moved the source to tools/perf/page_sets/tough_s
4
5 #include <algorithm>
6
7 #include "ppapi/c/pp_input_event.h"
8 #include "ppapi/cpp/graphics_2d.h"
9 #include "ppapi/cpp/image_data.h"
10 #include "ppapi/cpp/input_event.h"
11 #include "ppapi/cpp/instance.h"
12 #include "ppapi/cpp/logging.h"
dmichael (off chromium) 2014/05/29 16:28:04 You don't seem to be using this?
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 Done.
13 #include "ppapi/cpp/module.h"
14 #include "ppapi/cpp/private/input_event_private.h"
15 #include "ppapi/cpp/size.h"
16 #include "ppapi/cpp/view.h"
17 #include "ppapi/utility/graphics/paint_manager.h"
18
19 pp::Rect SquareForTouchPoint(int x, int y) {
20 return PP_MakeRectFromXYWH(x - 30, y - 30,
21 30 * 2 + 1, 30 * 2 + 1);
22 }
23
24 static void FillRect(pp::ImageData* image,
25 int left, int top, int width, int height,
26 uint32_t color) {
dmichael (off chromium) 2014/05/29 16:28:04 nit: params in a function declaration or definitio
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 Done.
27 for (int y = std::max(0, top);
28 y < std::min(image->size().height() - 1, top + height);
29 y++) {
30 for (int x = std::max(0, left);
31 x < std::min(image->size().width() - 1, left + width);
32 x++)
dmichael (off chromium) 2014/05/29 16:28:04 nit: since the "for" covers multiple lines, we wou
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 Done.
33 *image->GetAddr32(pp::Point(x, y)) = color;
34 }
35 }
36
37 class MyInstance : public pp::Instance, public pp::PaintManager::Client {
38 public:
39 MyInstance(PP_Instance instance)
dmichael (off chromium) 2014/05/29 16:28:04 nit: explicit
Yufeng Shen (Slow to review) 2014/05/29 18:29:20 Done.
40 : pp::Instance(instance),
41 paint_manager_() {
42 paint_manager_.Initialize(this, this, false);
43 RequestInputEvents(PP_INPUTEVENT_CLASS_TOUCH);
44 pp::InputEventPrivate::StartTrackingLatency(pp::InstanceHandle(instance));
dmichael (off chromium) 2014/05/29 16:28:04 If this stays as an example in ppapi/examples, you
45 }
46
47 virtual bool HandleInputEvent(const pp::InputEvent& event) {
48 switch (event.GetType()) {
49 case PP_INPUTEVENT_TYPE_TOUCHSTART:
50 case PP_INPUTEVENT_TYPE_TOUCHEND:
51 case PP_INPUTEVENT_TYPE_TOUCHCANCEL: {
52 pp::InputEventPrivate private_event(event);
53 private_event.TraceInputLatency(false);
54 return true;
55 }
56
57 case PP_INPUTEVENT_TYPE_TOUCHMOVE: {
58 pp::TouchInputEvent touch(event);
59 uint32_t count = touch.GetTouchCount(PP_TOUCHLIST_TYPE_CHANGEDTOUCHES);
60 if (count > 0) {
61 pp::TouchPoint point = touch.GetTouchByIndex(
62 PP_TOUCHLIST_TYPE_CHANGEDTOUCHES, 0);
63 UpdateSquareTouch(static_cast<int>(point.position().x()),
64 static_cast<int>(point.position().y()));
65 pp::InputEventPrivate private_event(event);
66 private_event.TraceInputLatency(true);
67 } else {
68 pp::InputEventPrivate private_event(event);
69 private_event.TraceInputLatency(false);
70 }
71 return true;
72 }
73 default:
74 return false;
75 }
76 }
77
78 virtual void DidChangeView(const pp::View& view) {
79 paint_manager_.SetSize(view.GetRect().size());
80 }
81
82 // PaintManager::Client implementation.
83 virtual bool OnPaint(pp::Graphics2D& graphics_2d,
84 const std::vector<pp::Rect>& paint_rects,
85 const pp::Rect& paint_bounds) {
86 pp::ImageData updated_image(this, PP_IMAGEDATAFORMAT_BGRA_PREMUL,
87 paint_bounds.size(), false);
88
89 for (size_t i = 0; i < paint_rects.size(); i++) {
90 // Since our image is just the invalid region, we need to offset the
91 // areas we paint by that much. This is just a light blue background.
92 FillRect(&updated_image,
93 paint_rects[i].x(),
94 paint_rects[i].y(),
95 paint_rects[i].width(),
96 paint_rects[i].height(),
97 0xFF000000);
98 }
99
100 graphics_2d.PaintImageData(updated_image, paint_bounds.point());
101 return true;
102 }
103
104 private:
105 void UpdateSquareTouch(int x, int y) {
106 paint_manager_.InvalidateRect(SquareForTouchPoint(x, y));
107 }
108
109 pp::PaintManager paint_manager_;
110 };
111
112 class MyModule : public pp::Module {
113 public:
114 virtual pp::Instance* CreateInstance(PP_Instance instance) {
115 return new MyInstance(instance);
116 }
117 };
118
119 namespace pp {
120
121 Module* CreateModule() {
122 return new MyModule();
123 }
124
125 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698