OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "ppapi/proxy/video_decoder_resource.h" | 5 #include "ppapi/proxy/video_decoder_resource.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "gpu/command_buffer/common/mailbox.h" | 10 #include "gpu/command_buffer/common/mailbox.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "ppapi/shared_impl/resource_tracker.h" | 22 #include "ppapi/shared_impl/resource_tracker.h" |
23 #include "ppapi/thunk/enter.h" | 23 #include "ppapi/thunk/enter.h" |
24 | 24 |
25 using ppapi::thunk::EnterResourceNoLock; | 25 using ppapi::thunk::EnterResourceNoLock; |
26 using ppapi::thunk::PPB_Graphics3D_API; | 26 using ppapi::thunk::PPB_Graphics3D_API; |
27 using ppapi::thunk::PPB_VideoDecoder_API; | 27 using ppapi::thunk::PPB_VideoDecoder_API; |
28 | 28 |
29 namespace ppapi { | 29 namespace ppapi { |
30 namespace proxy { | 30 namespace proxy { |
31 | 31 |
32 namespace { | |
33 | |
34 // The maximum number of pictures that the client can pass in for | |
35 // min_picture_count, just as a sanity check on the argument. | |
36 // This should match the constant of the same name in test_video_decoder.cc. | |
37 const uint32_t kMaximumPictureCount = 100; | |
jln (very slow on Chromium)
2015/08/17 21:44:39
What happens if they don't match?
Could you expos
lpique
2015/08/17 23:57:07
The test in test_video_decoder.cc will fail, since
| |
38 | |
39 } // namespace | |
40 | |
32 VideoDecoderResource::ShmBuffer::ShmBuffer( | 41 VideoDecoderResource::ShmBuffer::ShmBuffer( |
33 scoped_ptr<base::SharedMemory> shm_ptr, | 42 scoped_ptr<base::SharedMemory> shm_ptr, |
34 uint32_t size, | 43 uint32_t size, |
35 uint32_t shm_id) | 44 uint32_t shm_id) |
36 : shm(shm_ptr.Pass()), addr(NULL), shm_id(shm_id) { | 45 : shm(shm_ptr.Pass()), addr(NULL), shm_id(shm_id) { |
37 if (shm->Map(size)) | 46 if (shm->Map(size)) |
38 addr = shm->memory(); | 47 addr = shm->memory(); |
39 } | 48 } |
40 | 49 |
41 VideoDecoderResource::ShmBuffer::~ShmBuffer() { | 50 VideoDecoderResource::ShmBuffer::~ShmBuffer() { |
(...skipping 13 matching lines...) Expand all Loading... | |
55 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { | 64 : decode_id(decode_id), texture_id(texture_id), visible_rect(visible_rect) { |
56 } | 65 } |
57 | 66 |
58 VideoDecoderResource::Picture::~Picture() { | 67 VideoDecoderResource::Picture::~Picture() { |
59 } | 68 } |
60 | 69 |
61 VideoDecoderResource::VideoDecoderResource(Connection connection, | 70 VideoDecoderResource::VideoDecoderResource(Connection connection, |
62 PP_Instance instance) | 71 PP_Instance instance) |
63 : PluginResource(connection, instance), | 72 : PluginResource(connection, instance), |
64 num_decodes_(0), | 73 num_decodes_(0), |
74 min_picture_count_(0), | |
65 get_picture_(NULL), | 75 get_picture_(NULL), |
66 get_picture_0_1_(NULL), | 76 get_picture_0_1_(NULL), |
67 gles2_impl_(NULL), | 77 gles2_impl_(NULL), |
68 initialized_(false), | 78 initialized_(false), |
69 testing_(false), | 79 testing_(false), |
70 // Set |decoder_last_error_| to PP_OK after successful initialization. | 80 // Set |decoder_last_error_| to PP_OK after successful initialization. |
71 // This makes error checking a little more concise, since we can check | 81 // This makes error checking a little more concise, since we can check |
72 // that the decoder has been initialized and hasn't returned an error by | 82 // that the decoder has been initialized and hasn't returned an error by |
73 // just testing |decoder_last_error_|. | 83 // just testing |decoder_last_error_|. |
74 decoder_last_error_(PP_ERROR_FAILED) { | 84 decoder_last_error_(PP_ERROR_FAILED) { |
(...skipping 16 matching lines...) Expand all Loading... | |
91 int32_t VideoDecoderResource::Initialize0_1( | 101 int32_t VideoDecoderResource::Initialize0_1( |
92 PP_Resource graphics_context, | 102 PP_Resource graphics_context, |
93 PP_VideoProfile profile, | 103 PP_VideoProfile profile, |
94 PP_Bool allow_software_fallback, | 104 PP_Bool allow_software_fallback, |
95 scoped_refptr<TrackedCallback> callback) { | 105 scoped_refptr<TrackedCallback> callback) { |
96 return Initialize(graphics_context, | 106 return Initialize(graphics_context, |
97 profile, | 107 profile, |
98 allow_software_fallback | 108 allow_software_fallback |
99 ? PP_HARDWAREACCELERATION_WITHFALLBACK | 109 ? PP_HARDWAREACCELERATION_WITHFALLBACK |
100 : PP_HARDWAREACCELERATION_ONLY, | 110 : PP_HARDWAREACCELERATION_ONLY, |
111 0, | |
101 callback); | 112 callback); |
102 } | 113 } |
103 | 114 |
115 int32_t VideoDecoderResource::Initialize0_2( | |
116 PP_Resource graphics_context, | |
117 PP_VideoProfile profile, | |
118 PP_HardwareAcceleration acceleration, | |
119 scoped_refptr<TrackedCallback> callback) { | |
120 return Initialize(graphics_context, | |
121 profile, | |
122 acceleration, | |
123 0, | |
124 callback); | |
125 } | |
126 | |
104 int32_t VideoDecoderResource::Initialize( | 127 int32_t VideoDecoderResource::Initialize( |
105 PP_Resource graphics_context, | 128 PP_Resource graphics_context, |
106 PP_VideoProfile profile, | 129 PP_VideoProfile profile, |
107 PP_HardwareAcceleration acceleration, | 130 PP_HardwareAcceleration acceleration, |
131 uint32_t min_picture_count, | |
108 scoped_refptr<TrackedCallback> callback) { | 132 scoped_refptr<TrackedCallback> callback) { |
109 if (initialized_) | 133 if (initialized_) |
110 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
111 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) | 135 if (profile < 0 || profile > PP_VIDEOPROFILE_MAX) |
112 return PP_ERROR_BADARGUMENT; | 136 return PP_ERROR_BADARGUMENT; |
137 if (min_picture_count > kMaximumPictureCount) | |
bbudge
2015/08/19 18:47:05
You could keep this if you move the constant defin
| |
138 return PP_ERROR_BADARGUMENT; | |
113 if (initialize_callback_.get()) | 139 if (initialize_callback_.get()) |
114 return PP_ERROR_INPROGRESS; | 140 return PP_ERROR_INPROGRESS; |
115 if (!graphics_context) | 141 if (!graphics_context) |
116 return PP_ERROR_BADRESOURCE; | 142 return PP_ERROR_BADRESOURCE; |
117 | 143 |
144 min_picture_count_ = min_picture_count; | |
145 | |
118 HostResource host_resource; | 146 HostResource host_resource; |
119 if (!testing_) { | 147 if (!testing_) { |
120 // Create a new Graphics3D resource that can create texture resources to | 148 // Create a new Graphics3D resource that can create texture resources to |
121 // share with the plugin. We can't use the plugin's Graphics3D, since we | 149 // share with the plugin. We can't use the plugin's Graphics3D, since we |
122 // create textures on a proxy thread, and would interfere with the plugin. | 150 // create textures on a proxy thread, and would interfere with the plugin. |
123 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); | 151 thunk::EnterResourceCreationNoLock enter_create(pp_instance()); |
124 if (enter_create.failed()) | 152 if (enter_create.failed()) |
125 return PP_ERROR_FAILED; | 153 return PP_ERROR_FAILED; |
126 int32_t attrib_list[] = {PP_GRAPHICS3DATTRIB_NONE}; | 154 int32_t attrib_list[] = {PP_GRAPHICS3DATTRIB_NONE}; |
127 graphics3d_ = | 155 graphics3d_ = |
128 ScopedPPResource(ScopedPPResource::PassRef(), | 156 ScopedPPResource(ScopedPPResource::PassRef(), |
129 enter_create.functions()->CreateGraphics3D( | 157 enter_create.functions()->CreateGraphics3D( |
130 pp_instance(), graphics_context, attrib_list)); | 158 pp_instance(), graphics_context, attrib_list)); |
131 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(graphics3d_.get(), | 159 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(graphics3d_.get(), |
132 false); | 160 false); |
133 if (enter_graphics.failed()) | 161 if (enter_graphics.failed()) |
134 return PP_ERROR_BADRESOURCE; | 162 return PP_ERROR_BADRESOURCE; |
135 | 163 |
136 PPB_Graphics3D_Shared* ppb_graphics3d_shared = | 164 PPB_Graphics3D_Shared* ppb_graphics3d_shared = |
137 static_cast<PPB_Graphics3D_Shared*>(enter_graphics.object()); | 165 static_cast<PPB_Graphics3D_Shared*>(enter_graphics.object()); |
138 gles2_impl_ = ppb_graphics3d_shared->gles2_impl(); | 166 gles2_impl_ = ppb_graphics3d_shared->gles2_impl(); |
139 host_resource = ppb_graphics3d_shared->host_resource(); | 167 host_resource = ppb_graphics3d_shared->host_resource(); |
140 } | 168 } |
141 | 169 |
142 initialize_callback_ = callback; | 170 initialize_callback_ = callback; |
143 | 171 |
144 Call<PpapiPluginMsg_VideoDecoder_InitializeReply>( | 172 Call<PpapiPluginMsg_VideoDecoder_InitializeReply>( |
145 RENDERER, | 173 RENDERER, |
146 PpapiHostMsg_VideoDecoder_Initialize( | 174 PpapiHostMsg_VideoDecoder_Initialize( |
147 host_resource, profile, acceleration), | 175 host_resource, profile, acceleration, min_picture_count), |
148 base::Bind(&VideoDecoderResource::OnPluginMsgInitializeComplete, this)); | 176 base::Bind(&VideoDecoderResource::OnPluginMsgInitializeComplete, this)); |
149 | 177 |
150 return PP_OK_COMPLETIONPENDING; | 178 return PP_OK_COMPLETIONPENDING; |
151 } | 179 } |
152 | 180 |
153 int32_t VideoDecoderResource::Decode(uint32_t decode_id, | 181 int32_t VideoDecoderResource::Decode(uint32_t decode_id, |
154 uint32_t size, | 182 uint32_t size, |
155 const void* buffer, | 183 const void* buffer, |
156 scoped_refptr<TrackedCallback> callback) { | 184 scoped_refptr<TrackedCallback> callback) { |
157 if (decoder_last_error_) | 185 if (decoder_last_error_) |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
352 testing_ = true; | 380 testing_ = true; |
353 } | 381 } |
354 | 382 |
355 void VideoDecoderResource::OnPluginMsgRequestTextures( | 383 void VideoDecoderResource::OnPluginMsgRequestTextures( |
356 const ResourceMessageReplyParams& params, | 384 const ResourceMessageReplyParams& params, |
357 uint32_t num_textures, | 385 uint32_t num_textures, |
358 const PP_Size& size, | 386 const PP_Size& size, |
359 uint32_t texture_target, | 387 uint32_t texture_target, |
360 const std::vector<gpu::Mailbox>& mailboxes) { | 388 const std::vector<gpu::Mailbox>& mailboxes) { |
361 DCHECK(num_textures); | 389 DCHECK(num_textures); |
390 DCHECK(num_textures >= min_picture_count_); | |
jln (very slow on Chromium)
2015/08/17 21:44:39
Is this correct as a DCHECK? What happens if an at
lpique
2015/08/17 23:57:07
I think so. With the rest of my changes, this shou
bbudge
2015/08/18 00:48:13
You definitely have to validate anything you recei
bbudge
2015/08/19 18:47:06
The DCHECKs here are OK for validating proxy corre
| |
362 DCHECK(mailboxes.empty() || mailboxes.size() == num_textures); | 391 DCHECK(mailboxes.empty() || mailboxes.size() == num_textures); |
363 std::vector<uint32_t> texture_ids(num_textures); | 392 std::vector<uint32_t> texture_ids(num_textures); |
364 if (gles2_impl_) { | 393 if (gles2_impl_) { |
365 gles2_impl_->GenTextures(num_textures, &texture_ids.front()); | 394 gles2_impl_->GenTextures(num_textures, &texture_ids.front()); |
366 for (uint32_t i = 0; i < num_textures; ++i) { | 395 for (uint32_t i = 0; i < num_textures; ++i) { |
367 gles2_impl_->ActiveTexture(GL_TEXTURE0); | 396 gles2_impl_->ActiveTexture(GL_TEXTURE0); |
368 gles2_impl_->BindTexture(texture_target, texture_ids[i]); | 397 gles2_impl_->BindTexture(texture_target, texture_ids[i]); |
369 gles2_impl_->TexParameteri( | 398 gles2_impl_->TexParameteri( |
370 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 399 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
371 gles2_impl_->TexParameteri( | 400 gles2_impl_->TexParameteri( |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
554 get_picture_0_1_->texture_target = texture_target; | 583 get_picture_0_1_->texture_target = texture_target; |
555 get_picture_0_1_->texture_size = texture_size; | 584 get_picture_0_1_->texture_size = texture_size; |
556 get_picture_0_1_ = NULL; | 585 get_picture_0_1_ = NULL; |
557 } | 586 } |
558 | 587 |
559 received_pictures_.pop(); | 588 received_pictures_.pop(); |
560 } | 589 } |
561 | 590 |
562 } // namespace proxy | 591 } // namespace proxy |
563 } // namespace ppapi | 592 } // namespace ppapi |
OLD | NEW |