| 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 14 matching lines...) Expand all Loading... |
| 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 ScopedPPResource& layer, | 31 const ScopedPPResource& layer, |
| 32 const ScopedPPResource& context, | 32 const ScopedPPResource& context, |
| 33 uint32_t texture, | 33 uint32_t texture, |
| 34 const scoped_refptr<TrackedCallback>& release_callback, | 34 const scoped_refptr<TrackedCallback>& release_callback, |
| 35 int32_t result, | |
| 36 uint32_t sync_point, | 35 uint32_t sync_point, |
| 37 bool is_lost) { | 36 bool is_lost) { |
| 38 if (!TrackedCallback::IsPending(release_callback)) | 37 if (!TrackedCallback::IsPending(release_callback)) |
| 39 return; | 38 return; |
| 40 | 39 |
| 41 if (result != PP_OK) { | |
| 42 release_callback->Run(result); | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 do { | 40 do { |
| 47 if (!sync_point) | 41 if (!sync_point) |
| 48 break; | 42 break; |
| 49 | 43 |
| 50 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); | 44 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); |
| 51 if (enter.failed()) | 45 if (enter.failed()) |
| 52 break; | 46 break; |
| 53 | 47 |
| 54 PPB_Graphics3D_Shared* graphics = | 48 PPB_Graphics3D_Shared* graphics = |
| 55 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 49 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 56 | 50 |
| 57 GLES2Implementation* gl = graphics->gles2_impl(); | 51 GLES2Implementation* gl = graphics->gles2_impl(); |
| 58 gl->WaitSyncPointCHROMIUM(sync_point); | 52 gl->WaitSyncPointCHROMIUM(sync_point); |
| 59 } while (false); | 53 } while (false); |
| 60 | 54 |
| 61 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); | 55 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); |
| 62 } | 56 } |
| 63 | 57 |
| 64 void OnImageReleased( | 58 void OnImageReleased( |
| 65 const ScopedPPResource& layer, | 59 const ScopedPPResource& layer, |
| 66 const ScopedPPResource& image, | 60 const ScopedPPResource& image, |
| 67 const scoped_refptr<TrackedCallback>& release_callback, | 61 const scoped_refptr<TrackedCallback>& release_callback, |
| 68 int32_t result, | |
| 69 uint32_t sync_point, | 62 uint32_t sync_point, |
| 70 bool is_lost) { | 63 bool is_lost) { |
| 71 if (!TrackedCallback::IsPending(release_callback)) | 64 if (!TrackedCallback::IsPending(release_callback)) |
| 72 return; | 65 return; |
| 73 release_callback->Run(result); | 66 release_callback->Run(PP_OK); |
| 74 } | 67 } |
| 75 | 68 |
| 76 } // namespace | 69 } // namespace |
| 77 | 70 |
| 78 CompositorLayerResource::CompositorLayerResource( | 71 CompositorLayerResource::CompositorLayerResource( |
| 79 Connection connection, | 72 Connection connection, |
| 80 PP_Instance instance, | 73 PP_Instance instance, |
| 81 const CompositorResource* compositor) | 74 const CompositorResource* compositor) |
| 82 : PluginResource(connection, instance), | 75 : PluginResource(connection, instance), |
| 83 compositor_(compositor), | 76 compositor_(compositor), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 105 if (compositor_->IsInProgress()) | 98 if (compositor_->IsInProgress()) |
| 106 return PP_ERROR_INPROGRESS; | 99 return PP_ERROR_INPROGRESS; |
| 107 | 100 |
| 108 if (!SetType(TYPE_COLOR)) | 101 if (!SetType(TYPE_COLOR)) |
| 109 return PP_ERROR_BADARGUMENT; | 102 return PP_ERROR_BADARGUMENT; |
| 110 DCHECK(data_.color); | 103 DCHECK(data_.color); |
| 111 | 104 |
| 112 if (!size) | 105 if (!size) |
| 113 return PP_ERROR_BADARGUMENT; | 106 return PP_ERROR_BADARGUMENT; |
| 114 | 107 |
| 108 |
| 115 data_.color->red = clamp(red); | 109 data_.color->red = clamp(red); |
| 116 data_.color->green = clamp(green); | 110 data_.color->green = clamp(green); |
| 117 data_.color->blue = clamp(blue); | 111 data_.color->blue = clamp(blue); |
| 118 data_.color->alpha = clamp(alpha); | 112 data_.color->alpha = clamp(alpha); |
| 119 data_.common.size = *size; | 113 data_.common.size = *size; |
| 120 | 114 |
| 121 return PP_OK; | 115 return PP_OK; |
| 122 } | 116 } |
| 123 | 117 |
| 124 int32_t CompositorLayerResource::SetTexture( | 118 int32_t CompositorLayerResource::SetTexture( |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // Set the source size to image's size. It will be used to verify | 200 // Set the source size to image's size. It will be used to verify |
| 207 // the source_rect passed to SetSourceRect(). | 201 // the source_rect passed to SetSourceRect(). |
| 208 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); | 202 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); |
| 209 | 203 |
| 210 data_.common.size = size ? *size : desc.size; | 204 data_.common.size = size ? *size : desc.size; |
| 211 data_.common.resource_id = compositor_->GenerateResourceId(); | 205 data_.common.resource_id = compositor_->GenerateResourceId(); |
| 212 data_.image->resource = enter.resource()->host_resource().host_resource(); | 206 data_.image->resource = enter.resource()->host_resource().host_resource(); |
| 213 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 207 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
| 214 data_.image->source_rect.size = source_size_; | 208 data_.image->source_rect.size = source_size_; |
| 215 | 209 |
| 216 // If the PP_Resource of this layer is released by the plugin, the | |
| 217 // release_callback will be aborted immediately, but the texture or image | |
| 218 // in this layer may still being used by chromium compositor. So we have to | |
| 219 // use ScopedPPResource to keep this resource alive until the texture or image | |
| 220 // is released by the chromium compositor. | |
| 221 release_callback_ = base::Bind( | 210 release_callback_ = base::Bind( |
| 222 &OnImageReleased, | 211 &OnImageReleased, |
| 223 ScopedPPResource(pp_resource()), // Keep layer alive. | 212 ScopedPPResource(pp_resource()), // Keep layer alive. |
| 224 ScopedPPResource(image_data), // Keep image_data alive. | 213 ScopedPPResource(image_data), // Keep image_data alive. |
| 225 release_callback); | 214 release_callback); |
| 226 | 215 |
| 227 return PP_OK_COMPLETIONPENDING; | 216 return PP_OK_COMPLETIONPENDING; |
| 228 } | 217 } |
| 229 | 218 |
| 230 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { | 219 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 } | 326 } |
| 338 | 327 |
| 339 // Should not be reached. | 328 // Should not be reached. |
| 340 DCHECK(false); | 329 DCHECK(false); |
| 341 return false; | 330 return false; |
| 342 } | 331 } |
| 343 | 332 |
| 344 int32_t CompositorLayerResource::CheckForSetTextureAndImage( | 333 int32_t CompositorLayerResource::CheckForSetTextureAndImage( |
| 345 LayerType type, | 334 LayerType type, |
| 346 const scoped_refptr<TrackedCallback>& release_callback) { | 335 const scoped_refptr<TrackedCallback>& release_callback) { |
| 347 if (!compositor_) | 336 if (!compositor_) |
| 348 return PP_ERROR_BADRESOURCE; | 337 return PP_ERROR_BADRESOURCE; |
| 349 | 338 |
| 350 if (compositor_->IsInProgress()) | 339 if (compositor_->IsInProgress()) |
| 351 return PP_ERROR_INPROGRESS; | 340 return PP_ERROR_INPROGRESS; |
| 352 | 341 |
| 353 if (!SetType(type)) | 342 if (!SetType(type)) |
| 354 return PP_ERROR_BADARGUMENT; | 343 return PP_ERROR_BADARGUMENT; |
| 355 | 344 |
| 356 // The layer's image has been set and it is not committed. | 345 // The layer's image has been set and it is not committed. |
| 357 if (!release_callback_.is_null()) | 346 if (!release_callback_.is_null()) |
| 358 return PP_ERROR_INPROGRESS; | 347 return PP_ERROR_INPROGRESS; |
| 359 | 348 |
| 360 // Do not allow using a block callback as a release callback. | 349 // Do not allow using a block callback as a release callback. |
| 361 if (release_callback->is_blocking()) | 350 if (release_callback->is_blocking()) |
| 362 return PP_ERROR_BADARGUMENT; | 351 return PP_ERROR_BADARGUMENT; |
| 363 | 352 |
| 364 return PP_OK; | 353 return PP_OK; |
| 365 } | 354 } |
| 366 | 355 |
| 367 } // namespace proxy | 356 } // namespace proxy |
| 368 } // namespace ppapi | 357 } // namespace ppapi |
| OLD | NEW |