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

Side by Side Diff: services/gfx/compositor/backend/gpu_rasterizer.h

Issue 1995873002: Mozart: Improve tracing and backpressure. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: address review comments Created 4 years, 7 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
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 #ifndef SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_ 5 #ifndef SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_
6 #define SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_ 6 #define SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "base/callback.h"
11 #include "base/macros.h" 10 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
14 #include "base/task_runner.h"
15 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
16 #include "mojo/gpu/gl_context.h" 14 #include "mojo/gpu/gl_context.h"
17 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/services/gpu/interfaces/context_provider.mojom.h" 16 #include "mojo/services/gpu/interfaces/context_provider.mojom.h"
19 #include "mojo/skia/ganesh_context.h" 17 #include "mojo/skia/ganesh_context.h"
20 #include "mojo/skia/ganesh_framebuffer_surface.h" 18 #include "mojo/skia/ganesh_framebuffer_surface.h"
21 19
22 namespace compositor { 20 namespace compositor {
23 21
24 class RenderFrame; 22 class RenderFrame;
25 class VsyncScheduler;
26 23
27 // Ganesh-based rasterizer which runs on a separate thread from the compositor. 24 // Ganesh-based rasterizer.
28 // Calls into this object, including its creation, must be posted to the 25 // Maintains a GL context and draws frames on demand.
29 // correct message loop by the output. 26 //
27 // This object runs on a separate thread from the rest of the compositor.
28 // It is not threadsafe; all calls into this object, including its creation,
29 // must run on the rasterizer thread.
30 class GpuRasterizer : public mojo::ViewportParameterListener, 30 class GpuRasterizer : public mojo::ViewportParameterListener,
31 public mojo::GLContext::Observer { 31 public mojo::GLContext::Observer {
32 public: 32 public:
33 // Callback invoked when a frame completes. 33 // Callbacks from the rasterizer.
34 // |presented| is true if the frame was actually presented, false if 34 // These calls always run on the rasterizer thread.
35 // the frame was discarded. 35 class Callbacks {
36 using FrameCallback = base::Callback<void(bool presented)>; 36 public:
37 virtual ~Callbacks() {}
38
39 // Called when the rasterizer is ready to start drawing.
40 // May be called repeatedly with new parameters.
41 virtual void OnRasterizerReady(int64_t vsync_timebase,
42 int64_t vsync_interval) = 0;
43
44 // Called when the rasterizer can't draw anymore.
45 virtual void OnRasterizerSuspended() = 0;
46
47 // Called when the rasterizer finished drawing a frame.
48 // |presented| is true if the frame was actually presented, false if
49 // the frame was discarded.
50 virtual void OnRasterizerFinishedDraw(bool presented) = 0;
51
52 // Called when an unrecoverable error occurs and the rasterizer needs
53 // to be shut down soon.
54 virtual void OnRasterizerError() = 0;
55 };
37 56
38 GpuRasterizer(mojo::ContextProviderPtr context_provider, 57 GpuRasterizer(mojo::ContextProviderPtr context_provider,
39 const scoped_refptr<VsyncScheduler>& scheduler, 58 Callbacks* callbacks);
40 const scoped_refptr<base::TaskRunner>& task_runner,
41 const base::Closure& error_callback);
42 ~GpuRasterizer() override; 59 ~GpuRasterizer() override;
43 60
44 // Submits a frame to be drawn. 61 // Draws the specified frame.
45 // If the GL context isn't ready yet, the frame will be retained unless 62 // Each frame will be acknowledged by a called to |OnRasterizerFinishedDraw|
46 // superceded by another frame. 63 // in the order submitted. The rasterizer must be in a ready state.
47 void SubmitFrame(const scoped_refptr<RenderFrame>& frame, 64 void DrawFrame(const scoped_refptr<RenderFrame>& frame);
48 const FrameCallback& frame_callback);
49 65
50 private: 66 private:
51 // |ViewportParameterListener|: 67 // |ViewportParameterListener|:
52 void OnVSyncParametersUpdated(int64_t timebase, int64_t interval) override; 68 void OnVSyncParametersUpdated(int64_t timebase, int64_t interval) override;
53 69
54 // |GLContext::Observer|: 70 // |GLContext::Observer|:
55 void OnContextLost() override; 71 void OnContextLost() override;
56 72
57 void CreateContext(); 73 void CreateContext();
58 void InitContext(mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer); 74 void InitContext(mojo::InterfaceHandle<mojo::CommandBuffer> command_buffer);
59 void AbandonContext(); 75 void AbandonContext();
60 void DestroyContext(); 76 void DestroyContext();
61 void RecreateContextAfterLoss(); 77 void RecreateContextAfterLoss();
62 void OnContextProviderConnectionError(); 78 void OnContextProviderConnectionError();
63 void OnViewportParameterTimeout(); 79 void OnViewportParameterTimeout();
64 void ApplyViewportParameters(); 80 void ApplyViewportParameters();
65 81
66 void DidEchoCallback(FrameCallback frame_callback); 82 void DrawFinished(bool presented);
67 void Draw(); 83 static void OnMGLEchoReply(void* context);
68
69 void PostErrorCallback();
70 84
71 mojo::ContextProviderPtr context_provider_; 85 mojo::ContextProviderPtr context_provider_;
72 scoped_refptr<VsyncScheduler> scheduler_; 86 Callbacks* callbacks_;
73 scoped_refptr<base::TaskRunner> task_runner_;
74 base::Closure error_callback_;
75 87
76 scoped_refptr<mojo::GLContext> gl_context_; 88 scoped_refptr<mojo::GLContext> gl_context_;
77 scoped_refptr<mojo::skia::GaneshContext> ganesh_context_; 89 scoped_refptr<mojo::skia::GaneshContext> ganesh_context_;
78 std::unique_ptr<mojo::skia::GaneshFramebufferSurface> ganesh_surface_; 90 std::unique_ptr<mojo::skia::GaneshFramebufferSurface> ganesh_surface_;
79 91
80 scoped_refptr<RenderFrame> frame_;
81 FrameCallback frame_callback_;
82
83 mojo::Binding<ViewportParameterListener> viewport_parameter_listener_binding_; 92 mojo::Binding<ViewportParameterListener> viewport_parameter_listener_binding_;
84 base::Timer viewport_parameter_timeout_; 93 base::Timer viewport_parameter_timeout_;
85 bool have_viewport_parameters_ = false; 94 bool have_viewport_parameters_ = false;
86 int64_t vsync_timebase_ = 0u; 95 int64_t vsync_timebase_ = 0u;
87 int64_t vsync_interval_ = 0u; 96 int64_t vsync_interval_ = 0u;
88 uint32_t frames_pending_ = 0u; 97
98 bool ready_ = false;
99 uint32_t total_frames_ = 0u;
100 uint32_t frames_in_progress_ = 0u;
89 101
90 base::WeakPtrFactory<GpuRasterizer> weak_ptr_factory_; 102 base::WeakPtrFactory<GpuRasterizer> weak_ptr_factory_;
91 103
92 DISALLOW_COPY_AND_ASSIGN(GpuRasterizer); 104 DISALLOW_COPY_AND_ASSIGN(GpuRasterizer);
93 }; 105 };
94 106
95 } // namespace compositor 107 } // namespace compositor
96 108
97 #endif // SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_ 109 #endif // SERVICES_GFX_COMPOSITOR_BACKEND_GPU_RASTERIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698