OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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. |
| 4 |
| 5 #include <ppapi/cpp/input_event.h> |
| 6 #include <ppapi/cpp/instance.h> |
| 7 #include <ppapi/cpp/module.h> |
| 8 #include <ppapi/cpp/point.h> |
| 9 #include <ppapi/cpp/var.h> |
| 10 #include <ppapi/cpp/var_array.h> |
| 11 #include <ppapi/cpp/var_dictionary.h> |
| 12 #include <ppapi/utility/completion_callback_factory.h> |
| 13 #include <stdint.h> |
| 14 #include <sys/time.h> |
| 15 |
| 16 #include <iomanip> |
| 17 #include <sstream> |
| 18 #include <string> |
| 19 #include <vector> |
| 20 |
| 21 #include "framework.h" |
| 22 |
| 23 void BenchmarkPost(Benchmark* b, double median, double range, void* data) { |
| 24 pp::VarDictionary benchmark; |
| 25 benchmark.Set("name", b->Name()); |
| 26 std::ostringstream result; |
| 27 result << std::fixed << std::setw(8) << std::setprecision(5) << |
| 28 median << " seconds"; |
| 29 benchmark.Set("result", result.str()); |
| 30 pp::VarDictionary message; |
| 31 message.Set("message", "benchmark_result"); |
| 32 message.Set("benchmark", benchmark); |
| 33 pp::Instance* instance = static_cast<pp::Instance*>(data); |
| 34 instance->PostMessage(message); |
| 35 } |
| 36 |
| 37 // Pepper framework |
| 38 |
| 39 class BenchmarksInstance : public pp::Instance { |
| 40 public: |
| 41 explicit BenchmarksInstance(PP_Instance instance) |
| 42 : pp::Instance(instance), |
| 43 callback_factory_(this) {} |
| 44 |
| 45 ~BenchmarksInstance() {} |
| 46 |
| 47 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 48 RequestInputEvents(PP_INPUTEVENT_CLASS_MOUSE); |
| 49 return true; |
| 50 } |
| 51 |
| 52 virtual void HandleMessage(const pp::Var& var) { |
| 53 if (var.is_dictionary()) { |
| 54 pp::VarDictionary dictionary(var); |
| 55 std::string message = dictionary.Get("message").AsString(); |
| 56 if (message == "run_benchmark") { |
| 57 BenchmarkSuite::Run("", BenchmarkPost, this); |
| 58 pp::VarDictionary message; |
| 59 message.Set("message", "benchmark_finish"); |
| 60 PostMessage(message); |
| 61 } |
| 62 } |
| 63 } |
| 64 |
| 65 private: |
| 66 pp::CompletionCallbackFactory<BenchmarksInstance> callback_factory_; |
| 67 }; |
| 68 |
| 69 class BenchmarksModule : public pp::Module { |
| 70 public: |
| 71 BenchmarksModule() : pp::Module() {} |
| 72 virtual ~BenchmarksModule() {} |
| 73 |
| 74 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 75 return new BenchmarksInstance(instance); |
| 76 } |
| 77 }; |
| 78 |
| 79 |
| 80 namespace pp { |
| 81 Module* CreateModule() { return new BenchmarksModule(); } |
| 82 } // namespace pp |
OLD | NEW |