1 // Copyright (c) 2012 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 #ifndef CONTENT_RENDERER_GPU_BENCHMARKING_EXTENSION_H_ 6 #define CONTENT_RENDERER_GPU_BENCHMARKING_EXTENSION_H_ 7 8 #include "base/macros.h" 9 #include "base/memory/weak_ptr.h" 10 #include "content/common/input/input_injector.mojom.h" 11 #include "gin/wrappable.h" 12 #include "mojo/public/cpp/bindings/remote.h" 13 14 namespace gin { 15 class Arguments; 16 } 17 18 namespace v8 { 19 class Isolate; 20 class Object; 21 } // namespace v8 22 23 namespace content { 24 25 class RenderFrameImpl; 26 27 // gin class for gpu benchmarking 28 class GpuBenchmarking : public gin::Wrappable<GpuBenchmarking> { 29 public: 30 static gin::WrapperInfo kWrapperInfo; 31 static void Install(base::WeakPtr<RenderFrameImpl> frame); 32 33 private: 34 explicit GpuBenchmarking(base::WeakPtr<RenderFrameImpl> frame); 35 ~GpuBenchmarking() override; 36 void EnsureRemoteInterface(); 37 38 // gin::Wrappable. 39 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( 40 v8::Isolate* isolate) override; 41 42 // JavaScript handlers. 43 void SetNeedsDisplayOnAllLayers(); 44 void SetRasterizeOnlyVisibleContent(); 45 void PrintToSkPicture(v8::Isolate* isolate, const std::string& dirname); 46 void PrintPagesToSkPictures(v8::Isolate* isolate, 47 const std::string& filename); 48 void PrintPagesToXPS(v8::Isolate* isolate, const std::string& filename); 49 bool GestureSourceTypeSupported(int gesture_source_type); 50 51 // All arguments in these methods are in visual viewport coordinates. 52 bool SmoothScrollBy(gin::Arguments* args); 53 bool SmoothDrag(gin::Arguments* args); 54 bool Swipe(gin::Arguments* args); 55 bool ScrollBounce(gin::Arguments* args); 56 bool PinchBy(gin::Arguments* args); 57 bool Tap(gin::Arguments* args); 58 59 bool PointerActionSequence(gin::Arguments* args); 60 61 // The offset of the visual viewport *within* the layout viewport, in CSS 62 // pixels. i.e. As the user zooms in, these values don't change. 63 float VisualViewportX(); 64 float VisualViewportY(); 65 66 // The width and height of the visual viewport in CSS pixels. i.e. As the 67 // user zooms in, these get smaller (since the physical viewport is a fixed 68 // size, fewer CSS pixels fit into it). 69 float VisualViewportHeight(); 70 float VisualViewportWidth(); 71 72 // Returns the page scale factor applied as a result of pinch-zoom. 73 float PageScaleFactor(); 74 // Sets the page scale factor applied as a result of pinch-zoom. 75 void SetPageScaleFactor(float scale); 76 77 void SetBrowserControlsShown(bool shown); 78 79 void ClearImageCache(); 80 int RunMicroBenchmark(gin::Arguments* args); 81 bool SendMessageToMicroBenchmark(int id, v8::Local<v8::Object> message); 82 bool HasGpuChannel(); 83 bool HasGpuProcess(); 84 void CrashGpuProcess(); 85 void GetGpuDriverBugWorkarounds(gin::Arguments* args); 86 87 // Starts/stops the sampling profiler. StartProfiling takes one optional 88 // argument, which is a file name for saving the data (relative to `pwd` 89 // or %USERDIR%); if omitted, it defaults to "profile.pb". 90 // 91 // DO NOT USE THIS IN CHROMIUM TESTS -- we don't want to fill up the bots' 92 // hard drives with profile data. 93 void StartProfiling(gin::Arguments* args); 94 void StopProfiling(); 95 96 // Freezes a page, used to transition the page to the FROZEN lifecycle state. 97 void Freeze(); 98 99 // Register a callback that should be fired when the next swap completes. 100 // The callback is removed once it's executed. 101 bool AddSwapCompletionEventListener(gin::Arguments* args); 102 103 base::WeakPtr<RenderFrameImpl> render_frame_; 104 mojo::Remote<mojom::InputInjector> input_injector_; 105 DISALLOW_COPY_AND_ASSIGN(GpuBenchmarking); 106 }; 107 108 } // namespace content 109 110 #endif // CONTENT_RENDERER_GPU_BENCHMARKING_EXTENSION_H_ 111