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