| 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 #ifndef REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_3D_H_ |
| 6 #define REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_3D_H_ |
| 7 |
| 8 #include <deque> |
| 9 #include <string> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "ppapi/cpp/graphics_3d.h" |
| 15 #include "ppapi/cpp/instance_handle.h" |
| 16 #include "ppapi/cpp/video_decoder.h" |
| 17 #include "ppapi/utility/completion_callback_factory.h" |
| 18 #include "remoting/client/chromoting_stats.h" |
| 19 #include "remoting/client/plugin/pepper_video_renderer.h" |
| 20 #include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" |
| 21 #include "third_party/webrtc/modules/desktop_capture/desktop_region.h" |
| 22 |
| 23 struct PPB_OpenGLES2; |
| 24 |
| 25 namespace remoting { |
| 26 |
| 27 // PepperVideoRenderer that uses the PPB_VideoDecoder interface for video |
| 28 // decoding and Graphics3D for rendering. |
| 29 class PepperVideoRenderer3D : public PepperVideoRenderer { |
| 30 public: |
| 31 PepperVideoRenderer3D(); |
| 32 ~PepperVideoRenderer3D() override; |
| 33 |
| 34 // PepperVideoRenderer interface. |
| 35 bool Initialize(pp::Instance* instance, |
| 36 const ClientContext& context, |
| 37 EventHandler* event_handler) override; |
| 38 void OnViewChanged(const pp::View& view) override; |
| 39 void OnSessionConfig(const protocol::SessionConfig& config) override; |
| 40 ChromotingStats* GetStats() override; |
| 41 void ProcessVideoPacket(scoped_ptr<VideoPacket> packet, |
| 42 const base::Closure& done) override; |
| 43 |
| 44 private: |
| 45 class PendingPacket; |
| 46 class Picture; |
| 47 |
| 48 struct FrameDecodeTimestamp { |
| 49 FrameDecodeTimestamp(uint32_t frame_id, |
| 50 base::TimeTicks decode_started_time); |
| 51 uint32_t frame_id; |
| 52 base::TimeTicks decode_started_time; |
| 53 }; |
| 54 |
| 55 // Callback for pp::VideoDecoder::Initialize(). |
| 56 void OnInitialized(int32_t result); |
| 57 |
| 58 // Passes one picture from |pending_packets_| to the |video_decoder_|. |
| 59 void DecodeNextPacket(); |
| 60 |
| 61 // Callback for pp::VideoDecoder::Decode(). |
| 62 void OnDecodeDone(int32_t result); |
| 63 |
| 64 // Fetches next picture from the |video_decoder_|. |
| 65 void GetNextPicture(); |
| 66 |
| 67 // Callback for pp::VideoDecoder::GetPicture(). |
| 68 void OnPictureReady(int32_t result, PP_VideoPicture picture); |
| 69 |
| 70 // Copies |next_picture_| to |current_picture_| if |next_picture_| is set and |
| 71 // then renders |current_picture_|. Doesn't do anything if |need_repaint_| is |
| 72 // false. |
| 73 void PaintIfNeeded(); |
| 74 |
| 75 // Callback for pp::Graphics3D::SwapBuffers(). |
| 76 void OnPaintDone(int32_t result); |
| 77 |
| 78 // Initializes |shader_program_| for |texture_target|. |
| 79 void EnsureProgramForTexture(uint32_t texture_target); |
| 80 |
| 81 // Initializes |shader_program_| with the given shaders. |
| 82 void CreateProgram(const char* vertex_shader, const char* fragment_shader); |
| 83 |
| 84 // Creates a new shader and compiles |source| for it. |
| 85 void CreateShaderProgram(int type, const char* source); |
| 86 |
| 87 // CHECKs that the last OpenGL call has completed successfully. |
| 88 void CheckGLError(); |
| 89 |
| 90 EventHandler* event_handler_; |
| 91 |
| 92 pp::Graphics3D graphics_; |
| 93 const PPB_OpenGLES2* gles2_if_; |
| 94 pp::VideoDecoder video_decoder_; |
| 95 |
| 96 webrtc::DesktopSize frame_size_; |
| 97 webrtc::DesktopVector frame_dpi_; |
| 98 webrtc::DesktopRegion desktop_shape_; |
| 99 |
| 100 webrtc::DesktopSize view_size_; |
| 101 |
| 102 ChromotingStats stats_; |
| 103 int64 latest_input_event_timestamp_ ; |
| 104 |
| 105 bool initialization_finished_; |
| 106 bool decode_pending_; |
| 107 bool get_picture_pending_; |
| 108 bool paint_pending_; |
| 109 |
| 110 uint32_t latest_frame_id_; |
| 111 |
| 112 // Queue of packets that that have been received, but haven't been passed to |
| 113 // the decoder yet. |
| 114 std::deque<PendingPacket*> pending_packets_; |
| 115 |
| 116 // Timestamps for all frames currently being processed by the decoder. |
| 117 std::deque<FrameDecodeTimestamp> frame_decode_timestamps_; |
| 118 |
| 119 // The current picture shown on the screen or being rendered. Must be deleted |
| 120 // before |video_decoder_|. |
| 121 scoped_ptr<Picture> current_picture_; |
| 122 |
| 123 // The next picture to be rendered. PaintIfNeeded() will copy it to |
| 124 // |current_picture_| and render it after that. Must be deleted |
| 125 // before |video_decoder_|. |
| 126 scoped_ptr<Picture> next_picture_; |
| 127 |
| 128 // Set to true if the screen has been resized and needs to be repainted. |
| 129 bool force_repaint_; |
| 130 |
| 131 // Time the last paint operation was started. |
| 132 base::TimeTicks latest_paint_started_time_; |
| 133 |
| 134 // The texture type for which |shader_program| was initialized. Can be either |
| 135 // 0, GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE_ARB or GL_TEXTURE_EXTERNAL_OES. 0 |
| 136 // indicates that |shader_program_| hasn't been intialized. |
| 137 uint32_t current_shader_program_texture_target_; |
| 138 |
| 139 // Shader program ID. |
| 140 unsigned int shader_program_; |
| 141 |
| 142 // Location of the scale value to be passed to the |shader_program_|. |
| 143 int shader_texcoord_scale_location_; |
| 144 |
| 145 pp::CompletionCallbackFactory<PepperVideoRenderer3D> callback_factory_; |
| 146 |
| 147 DISALLOW_COPY_AND_ASSIGN(PepperVideoRenderer3D); |
| 148 }; |
| 149 |
| 150 } // namespace remoting |
| 151 |
| 152 #endif // REMOTING_CLIENT_PLUGIN_PEPPER_VIDEO_RENDERER_3D_H_ |
| OLD | NEW |