Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "ppapi/proxy/compositor_layer_resource.h" | 5 #include "ppapi/proxy/compositor_layer_resource.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "gpu/command_buffer/common/mailbox.h" | 9 #include "gpu/command_buffer/common/mailbox.h" |
| 10 #include "ppapi/proxy/compositor_resource.h" | 10 #include "ppapi/proxy/compositor_resource.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 namespace ppapi { | 21 namespace ppapi { |
| 22 namespace proxy { | 22 namespace proxy { |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 float clamp(float value) { | 26 float clamp(float value) { |
| 27 return std::min(std::max(value, 0.0f), 1.0f); | 27 return std::min(std::max(value, 0.0f), 1.0f); |
| 28 } | 28 } |
| 29 | 29 |
| 30 void OnTextureReleased( | 30 void OnTextureReleased( |
| 31 const scoped_refptr<CompositorResource> compositor, | |
| 31 const ScopedPPResource& layer, | 32 const ScopedPPResource& layer, |
| 32 const ScopedPPResource& context, | 33 const ScopedPPResource& context, |
| 33 uint32_t texture, | 34 uint32_t texture, |
| 34 const scoped_refptr<TrackedCallback>& release_callback, | 35 const scoped_refptr<TrackedCallback>& release_callback, |
| 35 uint32_t sync_point, | 36 uint32_t sync_point, |
| 36 bool is_lost) { | 37 bool is_lost) { |
| 37 if (!TrackedCallback::IsPending(release_callback)) | 38 if (!TrackedCallback::IsPending(release_callback)) |
| 38 return; | 39 return; |
| 39 | 40 |
| 40 do { | 41 do { |
| 41 if (!sync_point) | 42 if (!sync_point) |
| 42 break; | 43 break; |
| 43 | 44 |
| 44 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); | 45 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); |
| 45 if (enter.failed()) | 46 if (enter.failed()) |
| 46 break; | 47 break; |
| 47 | 48 |
| 48 PPB_Graphics3D_Shared* graphics = | 49 PPB_Graphics3D_Shared* graphics = |
| 49 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 50 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 50 | 51 |
| 51 GLES2Implementation* gl = graphics->gles2_impl(); | 52 GLES2Implementation* gl = graphics->gles2_impl(); |
| 52 gl->WaitSyncPointCHROMIUM(sync_point); | 53 gl->WaitSyncPointCHROMIUM(sync_point); |
| 53 } while (false); | 54 } while (false); |
| 54 | 55 |
| 55 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); | 56 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); |
| 56 } | 57 } |
| 57 | 58 |
| 58 void OnImageReleased( | 59 void OnImageReleased( |
| 60 const scoped_refptr<CompositorResource> compositor, | |
| 59 const ScopedPPResource& layer, | 61 const ScopedPPResource& layer, |
| 60 const ScopedPPResource& image, | 62 const ScopedPPResource& image, |
| 61 const scoped_refptr<TrackedCallback>& release_callback, | 63 const scoped_refptr<TrackedCallback>& release_callback, |
| 62 uint32_t sync_point, | 64 uint32_t sync_point, |
| 63 bool is_lost) { | 65 bool is_lost) { |
| 64 if (!TrackedCallback::IsPending(release_callback)) | 66 if (!TrackedCallback::IsPending(release_callback)) |
| 65 return; | 67 return; |
| 66 release_callback->Run(PP_OK); | 68 release_callback->Run(PP_OK); |
| 67 } | 69 } |
| 68 | 70 |
| 69 } // namespace | 71 } // namespace |
| 70 | 72 |
| 71 CompositorLayerResource::CompositorLayerResource( | 73 CompositorLayerResource::CompositorLayerResource( |
| 72 Connection connection, | 74 Connection connection, |
| 73 PP_Instance instance, | 75 PP_Instance instance, |
| 74 const CompositorResource* compositor) | 76 scoped_refptr<CompositorResource> compositor) |
| 75 : PluginResource(connection, instance), | 77 : PluginResource(connection, instance), |
| 76 compositor_(compositor), | 78 compositor_(compositor), |
| 77 source_size_(PP_MakeFloatSize(0.0f, 0.0f)) { | 79 source_size_(PP_MakeFloatSize(0.0f, 0.0f)) { |
| 78 } | 80 } |
| 79 | 81 |
| 80 CompositorLayerResource::~CompositorLayerResource() { | 82 CompositorLayerResource::~CompositorLayerResource() { |
| 81 DCHECK(!compositor_); | 83 DCHECK(!compositor_); |
| 82 DCHECK(release_callback_.is_null()); | 84 DCHECK(release_callback_.is_null()); |
| 83 } | 85 } |
| 84 | 86 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 98 if (compositor_->IsInProgress()) | 100 if (compositor_->IsInProgress()) |
| 99 return PP_ERROR_INPROGRESS; | 101 return PP_ERROR_INPROGRESS; |
| 100 | 102 |
| 101 if (!SetType(TYPE_COLOR)) | 103 if (!SetType(TYPE_COLOR)) |
| 102 return PP_ERROR_BADARGUMENT; | 104 return PP_ERROR_BADARGUMENT; |
| 103 DCHECK(data_.color); | 105 DCHECK(data_.color); |
| 104 | 106 |
| 105 if (!size) | 107 if (!size) |
| 106 return PP_ERROR_BADARGUMENT; | 108 return PP_ERROR_BADARGUMENT; |
| 107 | 109 |
| 108 | |
| 109 data_.color->red = clamp(red); | 110 data_.color->red = clamp(red); |
| 110 data_.color->green = clamp(green); | 111 data_.color->green = clamp(green); |
| 111 data_.color->blue = clamp(blue); | 112 data_.color->blue = clamp(blue); |
| 112 data_.color->alpha = clamp(alpha); | 113 data_.color->alpha = clamp(alpha); |
| 113 data_.common.size = *size; | 114 data_.common.size = *size; |
| 114 | 115 |
| 115 return PP_OK; | 116 return PP_OK; |
| 116 } | 117 } |
| 117 | 118 |
| 118 int32_t CompositorLayerResource::SetTexture( | 119 int32_t CompositorLayerResource::SetTexture( |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 131 | 132 |
| 132 if (!size || size->width <= 0 || size->height <= 0) | 133 if (!size || size->width <= 0 || size->height <= 0) |
| 133 return PP_ERROR_BADARGUMENT; | 134 return PP_ERROR_BADARGUMENT; |
| 134 | 135 |
| 135 PPB_Graphics3D_Shared* graphics = | 136 PPB_Graphics3D_Shared* graphics = |
| 136 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 137 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 137 | 138 |
| 138 GLES2Implementation* gl = graphics->gles2_impl(); | 139 GLES2Implementation* gl = graphics->gles2_impl(); |
| 139 | 140 |
| 140 // Generate a Mailbox for the texture. | 141 // Generate a Mailbox for the texture. |
| 141 gl->GenMailboxCHROMIUM( | 142 // gl->GenMailboxCHROMIUM( |
| 142 reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); | 143 // reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); |
| 144 // | |
| 145 // TODO(penghuang): Use gl->GenMailboxCHROMIUM() when the bug in | |
| 146 // nacl_secure_random() is fixed. | |
|
piman
2014/06/19 20:44:04
I thought that was getting fixed. Let's remove thi
Peng
2014/06/19 22:33:41
Done.
| |
| 147 static bool flag = false; | |
| 148 if (!flag) { | |
| 149 srand(time(NULL)); | |
| 150 flag = true; | |
| 151 } | |
| 152 uint8_t value = 1; | |
| 153 for (size_t i = 1; i < arraysize(data_.texture->mailbox.name); ++i) { | |
| 154 data_.texture->mailbox.name[i] = static_cast<uint8_t>(rand()); | |
| 155 value ^= data_.texture->mailbox.name[i]; | |
| 156 } | |
| 157 data_.texture->mailbox.name[0] = value; | |
| 143 gl->ProduceTextureDirectCHROMIUM( | 158 gl->ProduceTextureDirectCHROMIUM( |
| 144 texture, GL_TEXTURE_2D, | 159 texture, GL_TEXTURE_2D, |
| 145 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); | 160 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); |
| 146 | 161 |
| 147 // Set the source size to (1, 1). It will be used to verify the source_rect | 162 // Set the source size to (1, 1). It will be used to verify the source_rect |
| 148 // passed to SetSourceRect(). | 163 // passed to SetSourceRect(). |
| 149 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); | 164 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); |
| 150 | 165 |
| 151 data_.common.size = *size; | 166 data_.common.size = *size; |
| 152 data_.common.resource_id = compositor_->GenerateResourceId(); | 167 data_.common.resource_id = compositor_->GenerateResourceId(); |
| 153 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); | 168 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); |
| 154 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 169 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
| 155 data_.texture->source_rect.size = source_size_; | 170 data_.texture->source_rect.size = source_size_; |
| 156 | 171 |
| 157 // If the PP_Resource of this layer is released by the plugin, the | 172 // If the PP_Resource of this layer is released by the plugin, the |
| 158 // release_callback will be aborted immediately, but the texture or image | 173 // release_callback will be aborted immediately, but the texture or image |
| 159 // in this layer may still being used by chromium compositor. So we have to | 174 // in this layer may still being used by chromium compositor. So we have to |
| 160 // use ScopedPPResource to keep this resource alive until the texture or image | 175 // use ScopedPPResource to keep this resource alive until the texture or image |
| 161 // is released by the chromium compositor. | 176 // is released by the chromium compositor. And we need keep the compositor |
| 177 // alive, otherwise we will not receive the release IPC message for the | |
| 178 // texture. | |
|
piman
2014/06/19 20:44:04
maybe you should let the plugin do that.
Peng
2014/06/19 22:33:41
Done.
| |
| 162 release_callback_ = base::Bind( | 179 release_callback_ = base::Bind( |
| 163 &OnTextureReleased, | 180 &OnTextureReleased, |
| 181 compositor_, // Keep compositor alive. | |
| 164 ScopedPPResource(pp_resource()), // Keep layer alive. | 182 ScopedPPResource(pp_resource()), // Keep layer alive. |
| 165 ScopedPPResource(context), // Keep context alive | 183 ScopedPPResource(context), // Keep context alive |
| 166 texture, | 184 texture, |
| 167 release_callback); | 185 release_callback); |
| 168 | 186 |
| 169 return PP_OK_COMPLETIONPENDING; | 187 return PP_OK_COMPLETIONPENDING; |
| 170 } | 188 } |
| 171 | 189 |
| 172 int32_t CompositorLayerResource::SetImage( | 190 int32_t CompositorLayerResource::SetImage( |
| 173 PP_Resource image_data, | 191 PP_Resource image_data, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 200 // Set the source size to image's size. It will be used to verify | 218 // Set the source size to image's size. It will be used to verify |
| 201 // the source_rect passed to SetSourceRect(). | 219 // the source_rect passed to SetSourceRect(). |
| 202 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); | 220 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); |
| 203 | 221 |
| 204 data_.common.size = size ? *size : desc.size; | 222 data_.common.size = size ? *size : desc.size; |
| 205 data_.common.resource_id = compositor_->GenerateResourceId(); | 223 data_.common.resource_id = compositor_->GenerateResourceId(); |
| 206 data_.image->resource = enter.resource()->host_resource().host_resource(); | 224 data_.image->resource = enter.resource()->host_resource().host_resource(); |
| 207 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 225 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
| 208 data_.image->source_rect.size = source_size_; | 226 data_.image->source_rect.size = source_size_; |
| 209 | 227 |
| 228 // If the PP_Resource of this layer is released by the plugin, the | |
| 229 // release_callback will be aborted immediately, but the texture or image | |
| 230 // in this layer may still being used by chromium compositor. So we have to | |
| 231 // use ScopedPPResource to keep this resource alive until the texture or image | |
| 232 // is released by the chromium compositor. And we need keep the compositor | |
| 233 // alive, otherwise we will not receive the release IPC message for the image. | |
| 210 release_callback_ = base::Bind( | 234 release_callback_ = base::Bind( |
| 211 &OnImageReleased, | 235 &OnImageReleased, |
| 236 compositor_, // Keep compositor alive. | |
| 212 ScopedPPResource(pp_resource()), // Keep layer alive. | 237 ScopedPPResource(pp_resource()), // Keep layer alive. |
| 213 ScopedPPResource(image_data), // Keep image_data alive. | 238 ScopedPPResource(image_data), // Keep image_data alive. |
| 214 release_callback); | 239 release_callback); |
| 215 | 240 |
| 216 return PP_OK_COMPLETIONPENDING; | 241 return PP_OK_COMPLETIONPENDING; |
| 217 } | 242 } |
| 218 | 243 |
| 219 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { | 244 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { |
| 220 if (!compositor_) | 245 if (!compositor_) |
| 221 return PP_ERROR_BADRESOURCE; | 246 return PP_ERROR_BADRESOURCE; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 } | 351 } |
| 327 | 352 |
| 328 // Should not be reached. | 353 // Should not be reached. |
| 329 DCHECK(false); | 354 DCHECK(false); |
| 330 return false; | 355 return false; |
| 331 } | 356 } |
| 332 | 357 |
| 333 int32_t CompositorLayerResource::CheckForSetTextureAndImage( | 358 int32_t CompositorLayerResource::CheckForSetTextureAndImage( |
| 334 LayerType type, | 359 LayerType type, |
| 335 const scoped_refptr<TrackedCallback>& release_callback) { | 360 const scoped_refptr<TrackedCallback>& release_callback) { |
| 336 if (!compositor_) | 361 if (!compositor_) |
| 337 return PP_ERROR_BADRESOURCE; | 362 return PP_ERROR_BADRESOURCE; |
| 338 | 363 |
| 339 if (compositor_->IsInProgress()) | 364 if (compositor_->IsInProgress()) |
| 340 return PP_ERROR_INPROGRESS; | 365 return PP_ERROR_INPROGRESS; |
| 341 | 366 |
| 342 if (!SetType(type)) | 367 if (!SetType(type)) |
| 343 return PP_ERROR_BADARGUMENT; | 368 return PP_ERROR_BADARGUMENT; |
| 344 | 369 |
| 345 // The layer's image has been set and it is not committed. | 370 // The layer's image has been set and it is not committed. |
| 346 if (!release_callback_.is_null()) | 371 if (!release_callback_.is_null()) |
| 347 return PP_ERROR_INPROGRESS; | 372 return PP_ERROR_INPROGRESS; |
| 348 | 373 |
| 349 // Do not allow using a block callback as a release callback. | 374 // Do not allow using a block callback as a release callback. |
| 350 if (release_callback->is_blocking()) | 375 if (release_callback->is_blocking()) |
| 351 return PP_ERROR_BADARGUMENT; | 376 return PP_ERROR_BADARGUMENT; |
| 352 | 377 |
| 353 return PP_OK; | 378 return PP_OK; |
| 354 } | 379 } |
| 355 | 380 |
| 356 } // namespace proxy | 381 } // namespace proxy |
| 357 } // namespace ppapi | 382 } // namespace ppapi |
| OLD | NEW |