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

Side by Side Diff: remoting/client/plugin/pepper_video_renderer_3d.cc

Issue 2101833002: [Remoting Android] DisplayUpdaterFactory cleanups (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's Feedback Created 4 years, 5 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 2014 The Chromium Authors. All rights reserved. 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 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 #include "remoting/client/plugin/pepper_video_renderer_3d.h" 5 #include "remoting/client/plugin/pepper_video_renderer_3d.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 PP_VideoPicture picture_; 71 PP_VideoPicture picture_;
72 }; 72 };
73 73
74 PepperVideoRenderer3D::PepperVideoRenderer3D() : callback_factory_(this) {} 74 PepperVideoRenderer3D::PepperVideoRenderer3D() : callback_factory_(this) {}
75 75
76 PepperVideoRenderer3D::~PepperVideoRenderer3D() { 76 PepperVideoRenderer3D::~PepperVideoRenderer3D() {
77 if (shader_program_) 77 if (shader_program_)
78 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_); 78 gles2_if_->DeleteProgram(graphics_.pp_resource(), shader_program_);
79 } 79 }
80 80
81 bool PepperVideoRenderer3D::Initialize( 81 void PepperVideoRenderer3D::SetPepperContext(
82 pp::Instance* instance, 82 pp::Instance* instance,
83 const ClientContext& context, 83 EventHandler* event_handler) {
84 EventHandler* event_handler,
85 protocol::PerformanceTracker* perf_tracker) {
86 DCHECK(event_handler); 84 DCHECK(event_handler);
87 DCHECK(!event_handler_); 85 DCHECK(!event_handler_);
88 86
89 event_handler_ = event_handler; 87 event_handler_ = event_handler;
88 pp_instance_ = instance;
89 }
90
91 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) {
92 pp::Size size = view.GetRect().size();
93 float scale = view.GetDeviceScale();
94 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale));
95 graphics_.ResizeBuffers(view_size_.width(), view_size_.height());
96
97 force_repaint_ = true;
98 PaintIfNeeded();
99 }
100
101 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) {
102 debug_dirty_region_ = enable;
103 }
104
105 bool PepperVideoRenderer3D::Initialize(
106 const ClientContext& context,
107 protocol::PerformanceTracker* perf_tracker) {
90 perf_tracker_ = perf_tracker; 108 perf_tracker_ = perf_tracker;
91 109
92 const int32_t context_attributes[] = { 110 const int32_t context_attributes[] = {
93 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8, 111 PP_GRAPHICS3DATTRIB_ALPHA_SIZE, 8,
94 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8, 112 PP_GRAPHICS3DATTRIB_BLUE_SIZE, 8,
95 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8, 113 PP_GRAPHICS3DATTRIB_GREEN_SIZE, 8,
96 PP_GRAPHICS3DATTRIB_RED_SIZE, 8, 114 PP_GRAPHICS3DATTRIB_RED_SIZE, 8,
97 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0, 115 PP_GRAPHICS3DATTRIB_DEPTH_SIZE, 0,
98 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0, 116 PP_GRAPHICS3DATTRIB_STENCIL_SIZE, 0,
99 PP_GRAPHICS3DATTRIB_SAMPLES, 0, 117 PP_GRAPHICS3DATTRIB_SAMPLES, 0,
100 PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0, 118 PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS, 0,
101 PP_GRAPHICS3DATTRIB_WIDTH, 640, 119 PP_GRAPHICS3DATTRIB_WIDTH, 640,
102 PP_GRAPHICS3DATTRIB_HEIGHT, 480, 120 PP_GRAPHICS3DATTRIB_HEIGHT, 480,
103 PP_GRAPHICS3DATTRIB_NONE, 121 PP_GRAPHICS3DATTRIB_NONE,
104 }; 122 };
105 graphics_ = pp::Graphics3D(instance, context_attributes); 123 graphics_ = pp::Graphics3D(pp_instance_, context_attributes);
106 124
107 if (graphics_.is_null()) { 125 if (graphics_.is_null()) {
108 LOG(WARNING) << "Graphics3D interface is not available."; 126 LOG(WARNING) << "Graphics3D interface is not available.";
109 return false; 127 return false;
110 } 128 }
111 if (!instance->BindGraphics(graphics_)) { 129 if (!pp_instance_->BindGraphics(graphics_)) {
112 LOG(WARNING) << "Failed to bind Graphics3D."; 130 LOG(WARNING) << "Failed to bind Graphics3D.";
113 return false; 131 return false;
114 } 132 }
115 133
116 // Fetch the GLES2 interface to use to render frames. 134 // Fetch the GLES2 interface to use to render frames.
117 gles2_if_ = static_cast<const PPB_OpenGLES2*>( 135 gles2_if_ = static_cast<const PPB_OpenGLES2*>(
118 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)); 136 pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE));
119 CHECK(gles2_if_); 137 CHECK(gles2_if_);
120 138
121 video_decoder_ = pp::VideoDecoder(instance); 139 video_decoder_ = pp::VideoDecoder(pp_instance_);
122 if (video_decoder_.is_null()) { 140 if (video_decoder_.is_null()) {
123 LOG(WARNING) << "VideoDecoder interface is not available."; 141 LOG(WARNING) << "VideoDecoder interface is not available.";
124 return false; 142 return false;
125 } 143 }
126 144
127 PP_Resource graphics_3d = graphics_.pp_resource(); 145 PP_Resource graphics_3d = graphics_.pp_resource();
128 146
129 gles2_if_->ClearColor(graphics_3d, 1, 0, 0, 1); 147 gles2_if_->ClearColor(graphics_3d, 1, 0, 0, 1);
130 gles2_if_->Clear(graphics_3d, GL_COLOR_BUFFER_BIT); 148 gles2_if_->Clear(graphics_3d, GL_COLOR_BUFFER_BIT);
131 149
132 // Assign vertex positions and texture coordinates to buffers for use in 150 // Assign vertex positions and texture coordinates to buffers for use in
133 // shader program. 151 // shader program.
134 static const float kVertices[] = { 152 static const float kVertices[] = {
135 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates. 153 -1, -1, -1, 1, 1, -1, 1, 1, // Position coordinates.
136 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates. 154 0, 1, 0, 0, 1, 1, 1, 0, // Texture coordinates.
137 }; 155 };
138 156
139 GLuint buffer; 157 GLuint buffer;
140 gles2_if_->GenBuffers(graphics_3d, 1, &buffer); 158 gles2_if_->GenBuffers(graphics_3d, 1, &buffer);
141 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer); 159 gles2_if_->BindBuffer(graphics_3d, GL_ARRAY_BUFFER, buffer);
142 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices), 160 gles2_if_->BufferData(graphics_3d, GL_ARRAY_BUFFER, sizeof(kVertices),
143 kVertices, GL_STATIC_DRAW); 161 kVertices, GL_STATIC_DRAW);
144 162
145 CheckGLError(); 163 CheckGLError();
146 164
147 return true; 165 return true;
148 } 166 }
149 167
150 void PepperVideoRenderer3D::OnViewChanged(const pp::View& view) {
151 pp::Size size = view.GetRect().size();
152 float scale = view.GetDeviceScale();
153 view_size_.set(ceilf(size.width() * scale), ceilf(size.height() * scale));
154 graphics_.ResizeBuffers(view_size_.width(), view_size_.height());
155
156 force_repaint_ = true;
157 PaintIfNeeded();
158 }
159
160 void PepperVideoRenderer3D::EnableDebugDirtyRegion(bool enable) {
161 debug_dirty_region_ = enable;
162 }
163
164 void PepperVideoRenderer3D::OnSessionConfig( 168 void PepperVideoRenderer3D::OnSessionConfig(
165 const protocol::SessionConfig& config) { 169 const protocol::SessionConfig& config) {
166 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY; 170 PP_VideoProfile video_profile = PP_VIDEOPROFILE_VP8_ANY;
167 switch (config.video_config().codec) { 171 switch (config.video_config().codec) {
168 case protocol::ChannelConfig::CODEC_VP8: 172 case protocol::ChannelConfig::CODEC_VP8:
169 video_profile = PP_VIDEOPROFILE_VP8_ANY; 173 video_profile = PP_VIDEOPROFILE_VP8_ANY;
170 break; 174 break;
171 case protocol::ChannelConfig::CODEC_VP9: 175 case protocol::ChannelConfig::CODEC_VP9:
172 video_profile = PP_VIDEOPROFILE_VP9_ANY; 176 video_profile = PP_VIDEOPROFILE_VP9_ANY;
173 break; 177 break;
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader); 519 gles2_if_->AttachShader(graphics_.pp_resource(), shader_program_, shader);
516 gles2_if_->DeleteShader(graphics_.pp_resource(), shader); 520 gles2_if_->DeleteShader(graphics_.pp_resource(), shader);
517 } 521 }
518 522
519 void PepperVideoRenderer3D::CheckGLError() { 523 void PepperVideoRenderer3D::CheckGLError() {
520 GLenum error = gles2_if_->GetError(graphics_.pp_resource()); 524 GLenum error = gles2_if_->GetError(graphics_.pp_resource());
521 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error; 525 CHECK_EQ(error, static_cast<GLenum>(GL_NO_ERROR)) << "GL error: " << error;
522 } 526 }
523 527
524 } // namespace remoting 528 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698