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 27 matching lines...) Expand all Loading... | |
38 private: | 38 private: |
39 GLES2Implementation* gl_; | 39 GLES2Implementation* gl_; |
40 int32_t old_id_; | 40 int32_t old_id_; |
41 }; | 41 }; |
42 | 42 |
43 float clamp(float value) { | 43 float clamp(float value) { |
44 return std::min(std::max(value, 0.0f), 1.0f); | 44 return std::min(std::max(value, 0.0f), 1.0f); |
45 } | 45 } |
46 | 46 |
47 void OnTextureReleased( | 47 void OnTextureReleased( |
48 const scoped_refptr<CompositorResource> compositor, | |
48 const ScopedPPResource& layer, | 49 const ScopedPPResource& layer, |
49 const ScopedPPResource& context, | 50 const ScopedPPResource& context, |
50 uint32_t texture, | 51 uint32_t texture, |
51 const scoped_refptr<TrackedCallback>& release_callback, | 52 const scoped_refptr<TrackedCallback>& release_callback, |
52 uint32_t sync_point, | 53 uint32_t sync_point, |
53 bool is_lost) { | 54 bool is_lost) { |
54 if (!TrackedCallback::IsPending(release_callback)) | 55 if (!TrackedCallback::IsPending(release_callback)) |
55 return; | 56 return; |
56 | 57 |
57 do { | 58 do { |
58 if (!sync_point) | 59 if (!sync_point) |
59 break; | 60 break; |
60 | 61 |
61 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); | 62 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); |
62 if (enter.failed()) | 63 if (enter.failed()) |
63 break; | 64 break; |
64 | 65 |
65 PPB_Graphics3D_Shared* graphics = | 66 PPB_Graphics3D_Shared* graphics = |
66 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 67 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
67 | 68 |
68 GLES2Implementation* gl = graphics->gles2_impl(); | 69 GLES2Implementation* gl = graphics->gles2_impl(); |
69 gl->WaitSyncPointCHROMIUM(sync_point); | 70 gl->WaitSyncPointCHROMIUM(sync_point); |
70 } while (false); | 71 } while (false); |
71 | 72 |
72 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); | 73 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); |
73 } | 74 } |
74 | 75 |
75 void OnImageReleased( | 76 void OnImageReleased( |
77 const scoped_refptr<CompositorResource> compositor, | |
76 const ScopedPPResource& layer, | 78 const ScopedPPResource& layer, |
77 const ScopedPPResource& image, | 79 const ScopedPPResource& image, |
78 const scoped_refptr<TrackedCallback>& release_callback, | 80 const scoped_refptr<TrackedCallback>& release_callback, |
79 uint32_t sync_point, | 81 uint32_t sync_point, |
80 bool is_lost) { | 82 bool is_lost) { |
81 if (!TrackedCallback::IsPending(release_callback)) | 83 if (!TrackedCallback::IsPending(release_callback)) |
82 return; | 84 return; |
83 release_callback->Run(PP_OK); | 85 release_callback->Run(PP_OK); |
84 } | 86 } |
85 | 87 |
86 } // namespace | 88 } // namespace |
87 | 89 |
88 CompositorLayerResource::CompositorLayerResource( | 90 CompositorLayerResource::CompositorLayerResource( |
89 Connection connection, | 91 Connection connection, |
90 PP_Instance instance, | 92 PP_Instance instance, |
91 const CompositorResource* compositor) | 93 scoped_refptr<CompositorResource> compositor) |
92 : PluginResource(connection, instance), | 94 : PluginResource(connection, instance), |
93 compositor_(compositor), | 95 compositor_(compositor), |
94 source_size_(PP_MakeFloatSize(0.0f, 0.0f)) { | 96 source_size_(PP_MakeFloatSize(0.0f, 0.0f)) { |
95 } | 97 } |
96 | 98 |
97 CompositorLayerResource::~CompositorLayerResource() { | 99 CompositorLayerResource::~CompositorLayerResource() { |
98 DCHECK(!compositor_); | 100 DCHECK(!compositor_); |
99 DCHECK(release_callback_.is_null()); | 101 DCHECK(release_callback_.is_null()); |
100 } | 102 } |
101 | 103 |
102 thunk::PPB_CompositorLayer_API* | 104 thunk::PPB_CompositorLayer_API* |
103 CompositorLayerResource::AsPPB_CompositorLayer_API() { | 105 CompositorLayerResource::AsPPB_CompositorLayer_API() { |
104 return this; | 106 return this; |
105 } | 107 } |
106 | 108 |
107 int32_t CompositorLayerResource::SetColor(float red, | 109 int32_t CompositorLayerResource::SetColor(float red, |
108 float green, | 110 float green, |
109 float blue, | 111 float blue, |
110 float alpha, | 112 float alpha, |
111 const PP_Size* size) { | 113 const PP_Size* size) { |
112 if (!compositor_) | 114 if (!compositor_) |
113 return PP_ERROR_BADRESOURCE; | 115 return PP_ERROR_BADRESOURCE; |
114 | 116 |
117 CHECK(compositor_->bound_to_instance()); | |
piman
2014/06/18 00:55:24
no CHECK. Use DCHECK.
I don't think this DCHECK i
Peng
2014/06/18 02:35:03
If we allow an unbound compositor to have valid la
piman
2014/06/18 20:30:55
This should not happen. TextureLayer keeps a refer
| |
118 | |
115 if (compositor_->IsInProgress()) | 119 if (compositor_->IsInProgress()) |
116 return PP_ERROR_INPROGRESS; | 120 return PP_ERROR_INPROGRESS; |
117 | 121 |
118 if (!SetType(TYPE_COLOR)) | 122 if (!SetType(TYPE_COLOR)) |
119 return PP_ERROR_BADARGUMENT; | 123 return PP_ERROR_BADARGUMENT; |
120 DCHECK(data_.color); | 124 DCHECK(data_.color); |
121 | 125 |
122 if (!size) | 126 if (!size) |
123 return PP_ERROR_BADARGUMENT; | 127 return PP_ERROR_BADARGUMENT; |
124 | 128 |
125 | |
126 data_.color->red = clamp(red); | 129 data_.color->red = clamp(red); |
127 data_.color->green = clamp(green); | 130 data_.color->green = clamp(green); |
128 data_.color->blue = clamp(blue); | 131 data_.color->blue = clamp(blue); |
129 data_.color->alpha = clamp(alpha); | 132 data_.color->alpha = clamp(alpha); |
130 data_.common.size = *size; | 133 data_.common.size = *size; |
131 | 134 |
132 return PP_OK; | 135 return PP_OK; |
133 } | 136 } |
134 | 137 |
135 int32_t CompositorLayerResource::SetTexture( | 138 int32_t CompositorLayerResource::SetTexture( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 data_.common.resource_id = compositor_->GenerateResourceId(); | 173 data_.common.resource_id = compositor_->GenerateResourceId(); |
171 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); | 174 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); |
172 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 175 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
173 data_.texture->source_rect.size = source_size_; | 176 data_.texture->source_rect.size = source_size_; |
174 | 177 |
175 // If the PP_Resource of this layer is released by the plugin, the | 178 // If the PP_Resource of this layer is released by the plugin, the |
176 // release_callback will be aborted immediately, but the texture or image | 179 // release_callback will be aborted immediately, but the texture or image |
177 // in this layer may still being used by chromium compositor. So we have to | 180 // in this layer may still being used by chromium compositor. So we have to |
178 // use ScopedPPResource to keep this resource alive until the texture or image | 181 // use ScopedPPResource to keep this resource alive until the texture or image |
179 // is released by the chromium compositor. | 182 // is released by the chromium compositor. |
183 // We also need keep the compositor alive, otherwise we will not receive | |
184 // the release IPC message for the texture. | |
180 release_callback_ = base::Bind( | 185 release_callback_ = base::Bind( |
181 &OnTextureReleased, | 186 &OnTextureReleased, |
187 compositor_, // Keep compositor alive. | |
182 ScopedPPResource(pp_resource()), // Keep layer alive. | 188 ScopedPPResource(pp_resource()), // Keep layer alive. |
183 ScopedPPResource(context), // Keep context alive | 189 ScopedPPResource(context), // Keep context alive |
184 texture, | 190 texture, |
185 release_callback); | 191 release_callback); |
186 | 192 |
187 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
188 } | 194 } |
189 | 195 |
190 int32_t CompositorLayerResource::SetImage( | 196 int32_t CompositorLayerResource::SetImage( |
191 PP_Resource image_data, | 197 PP_Resource image_data, |
(...skipping 26 matching lines...) Expand all Loading... | |
218 // Set the source size to image's size. It will be used to verify | 224 // Set the source size to image's size. It will be used to verify |
219 // the source_rect passed to SetSourceRect(). | 225 // the source_rect passed to SetSourceRect(). |
220 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); | 226 source_size_ = PP_MakeFloatSize(desc.size.width, desc.size.height); |
221 | 227 |
222 data_.common.size = size ? *size : desc.size; | 228 data_.common.size = size ? *size : desc.size; |
223 data_.common.resource_id = compositor_->GenerateResourceId(); | 229 data_.common.resource_id = compositor_->GenerateResourceId(); |
224 data_.image->resource = enter.resource()->host_resource().host_resource(); | 230 data_.image->resource = enter.resource()->host_resource().host_resource(); |
225 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 231 data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
226 data_.image->source_rect.size = source_size_; | 232 data_.image->source_rect.size = source_size_; |
227 | 233 |
234 // If the PP_Resource of this layer is released by the plugin, the | |
235 // release_callback will be aborted immediately, but the texture or image | |
236 // in this layer may still being used by chromium compositor. So we have to | |
237 // use ScopedPPResource to keep this resource alive until the texture or image | |
238 // is released by the chromium compositor. | |
239 // We also need keep the compositor alive, otherwise we will not receive | |
240 // the release IPC message for the image. | |
228 release_callback_ = base::Bind( | 241 release_callback_ = base::Bind( |
229 &OnImageReleased, | 242 &OnImageReleased, |
243 compositor_, // Keep compositor alive. | |
230 ScopedPPResource(pp_resource()), // Keep layer alive. | 244 ScopedPPResource(pp_resource()), // Keep layer alive. |
231 ScopedPPResource(image_data), // Keep image_data alive. | 245 ScopedPPResource(image_data), // Keep image_data alive. |
232 release_callback); | 246 release_callback); |
233 | 247 |
234 return PP_OK_COMPLETIONPENDING; | 248 return PP_OK_COMPLETIONPENDING; |
235 } | 249 } |
236 | 250 |
237 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { | 251 int32_t CompositorLayerResource::SetClipRect(const PP_Rect* rect) { |
238 if (!compositor_) | 252 if (!compositor_) |
239 return PP_ERROR_BADRESOURCE; | 253 return PP_ERROR_BADRESOURCE; |
240 | 254 |
255 CHECK(compositor_->bound_to_instance()); | |
piman
2014/06/18 00:55:24
Same here, and other below.
Peng
2014/06/18 02:35:03
Same reason.
| |
256 | |
241 if (compositor_->IsInProgress()) | 257 if (compositor_->IsInProgress()) |
242 return PP_ERROR_INPROGRESS; | 258 return PP_ERROR_INPROGRESS; |
243 | 259 |
244 data_.common.clip_rect = rect ? *rect : PP_MakeRectFromXYWH(0, 0, 0, 0); | 260 data_.common.clip_rect = rect ? *rect : PP_MakeRectFromXYWH(0, 0, 0, 0); |
245 return PP_OK; | 261 return PP_OK; |
246 } | 262 } |
247 | 263 |
248 int32_t CompositorLayerResource::SetTransform(const float matrix[16]) { | 264 int32_t CompositorLayerResource::SetTransform(const float matrix[16]) { |
249 if (!compositor_) | 265 if (!compositor_) |
250 return PP_ERROR_BADRESOURCE; | 266 return PP_ERROR_BADRESOURCE; |
251 | 267 |
268 CHECK(compositor_->bound_to_instance()); | |
269 | |
252 if (compositor_->IsInProgress()) | 270 if (compositor_->IsInProgress()) |
253 return PP_ERROR_INPROGRESS; | 271 return PP_ERROR_INPROGRESS; |
254 | 272 |
255 std::copy(matrix, matrix + 16, data_.common.transform.matrix); | 273 std::copy(matrix, matrix + 16, data_.common.transform.matrix); |
256 return PP_OK; | 274 return PP_OK; |
257 } | 275 } |
258 | 276 |
259 int32_t CompositorLayerResource::SetOpacity(float opacity) { | 277 int32_t CompositorLayerResource::SetOpacity(float opacity) { |
260 if (!compositor_) | 278 if (!compositor_) |
261 return PP_ERROR_BADRESOURCE; | 279 return PP_ERROR_BADRESOURCE; |
262 | 280 |
281 CHECK(compositor_->bound_to_instance()); | |
282 | |
263 if (compositor_->IsInProgress()) | 283 if (compositor_->IsInProgress()) |
264 return PP_ERROR_INPROGRESS; | 284 return PP_ERROR_INPROGRESS; |
265 | 285 |
266 data_.common.opacity = clamp(opacity); | 286 data_.common.opacity = clamp(opacity); |
267 return PP_OK; | 287 return PP_OK; |
268 } | 288 } |
269 | 289 |
270 int32_t CompositorLayerResource::SetBlendMode(PP_BlendMode mode) { | 290 int32_t CompositorLayerResource::SetBlendMode(PP_BlendMode mode) { |
271 if (!compositor_) | 291 if (!compositor_) |
272 return PP_ERROR_BADRESOURCE; | 292 return PP_ERROR_BADRESOURCE; |
273 | 293 |
294 CHECK(compositor_->bound_to_instance()); | |
295 | |
274 if (compositor_->IsInProgress()) | 296 if (compositor_->IsInProgress()) |
275 return PP_ERROR_INPROGRESS; | 297 return PP_ERROR_INPROGRESS; |
276 | 298 |
277 switch (mode) { | 299 switch (mode) { |
278 case PP_BLENDMODE_NONE: | 300 case PP_BLENDMODE_NONE: |
279 case PP_BLENDMODE_SRC_OVER: | 301 case PP_BLENDMODE_SRC_OVER: |
280 data_.common.blend_mode = mode; | 302 data_.common.blend_mode = mode; |
281 return PP_OK; | 303 return PP_OK; |
282 } | 304 } |
283 return PP_ERROR_BADARGUMENT; | 305 return PP_ERROR_BADARGUMENT; |
284 } | 306 } |
285 | 307 |
286 int32_t CompositorLayerResource::SetSourceRect( | 308 int32_t CompositorLayerResource::SetSourceRect( |
287 const PP_FloatRect* rect) { | 309 const PP_FloatRect* rect) { |
288 if (!compositor_) | 310 if (!compositor_) |
289 return PP_ERROR_BADRESOURCE; | 311 return PP_ERROR_BADRESOURCE; |
290 | 312 |
313 CHECK(compositor_->bound_to_instance()); | |
314 | |
291 if (compositor_->IsInProgress()) | 315 if (compositor_->IsInProgress()) |
292 return PP_ERROR_INPROGRESS; | 316 return PP_ERROR_INPROGRESS; |
293 | 317 |
294 if (!rect || | 318 if (!rect || |
295 rect->point.x < 0.0f || | 319 rect->point.x < 0.0f || |
296 rect->point.y < 0.0f || | 320 rect->point.y < 0.0f || |
297 rect->point.x + rect->size.width > source_size_.width || | 321 rect->point.x + rect->size.width > source_size_.width || |
298 rect->point.y + rect->size.height > source_size_.height) { | 322 rect->point.y + rect->size.height > source_size_.height) { |
299 return PP_ERROR_BADARGUMENT; | 323 return PP_ERROR_BADARGUMENT; |
300 } | 324 } |
301 | 325 |
302 if (data_.texture) { | 326 if (data_.texture) { |
303 data_.texture->source_rect = *rect; | 327 data_.texture->source_rect = *rect; |
304 return PP_OK; | 328 return PP_OK; |
305 } | 329 } |
306 if (data_.image) { | 330 if (data_.image) { |
307 data_.image->source_rect = *rect; | 331 data_.image->source_rect = *rect; |
308 return PP_OK; | 332 return PP_OK; |
309 } | 333 } |
310 return PP_ERROR_BADARGUMENT; | 334 return PP_ERROR_BADARGUMENT; |
311 } | 335 } |
312 | 336 |
313 int32_t CompositorLayerResource::SetPremultipliedAlpha(PP_Bool premult) { | 337 int32_t CompositorLayerResource::SetPremultipliedAlpha(PP_Bool premult) { |
314 if (!compositor_) | 338 if (!compositor_) |
315 return PP_ERROR_BADRESOURCE; | 339 return PP_ERROR_BADRESOURCE; |
316 | 340 |
341 CHECK(compositor_->bound_to_instance()); | |
342 | |
317 if (compositor_->IsInProgress()) | 343 if (compositor_->IsInProgress()) |
318 return PP_ERROR_INPROGRESS; | 344 return PP_ERROR_INPROGRESS; |
319 | 345 |
320 if (data_.texture) { | 346 if (data_.texture) { |
321 data_.texture->premult_alpha = PP_ToBool(premult); | 347 data_.texture->premult_alpha = PP_ToBool(premult); |
322 return PP_OK; | 348 return PP_OK; |
323 } | 349 } |
324 return PP_ERROR_BADARGUMENT; | 350 return PP_ERROR_BADARGUMENT; |
325 } | 351 } |
326 | 352 |
(...skipping 17 matching lines...) Expand all Loading... | |
344 } | 370 } |
345 | 371 |
346 // Should not be reached. | 372 // Should not be reached. |
347 DCHECK(false); | 373 DCHECK(false); |
348 return false; | 374 return false; |
349 } | 375 } |
350 | 376 |
351 int32_t CompositorLayerResource::CheckForSetTextureAndImage( | 377 int32_t CompositorLayerResource::CheckForSetTextureAndImage( |
352 LayerType type, | 378 LayerType type, |
353 const scoped_refptr<TrackedCallback>& release_callback) { | 379 const scoped_refptr<TrackedCallback>& release_callback) { |
354 if (!compositor_) | 380 if (!compositor_) |
355 return PP_ERROR_BADRESOURCE; | 381 return PP_ERROR_BADRESOURCE; |
356 | 382 |
383 CHECK(compositor_->bound_to_instance()); | |
384 | |
357 if (compositor_->IsInProgress()) | 385 if (compositor_->IsInProgress()) |
358 return PP_ERROR_INPROGRESS; | 386 return PP_ERROR_INPROGRESS; |
359 | 387 |
360 if (!SetType(type)) | 388 if (!SetType(type)) |
361 return PP_ERROR_BADARGUMENT; | 389 return PP_ERROR_BADARGUMENT; |
362 | 390 |
363 // The layer's image has been set and it is not committed. | 391 // The layer's image has been set and it is not committed. |
364 if (!release_callback_.is_null()) | 392 if (!release_callback_.is_null()) |
365 return PP_ERROR_INPROGRESS; | 393 return PP_ERROR_INPROGRESS; |
366 | 394 |
367 // Do not allow using a block callback as a release callback. | 395 // Do not allow using a block callback as a release callback. |
368 if (release_callback->is_blocking()) | 396 if (release_callback->is_blocking()) |
369 return PP_ERROR_BADARGUMENT; | 397 return PP_ERROR_BADARGUMENT; |
370 | 398 |
371 return PP_OK; | 399 return PP_OK; |
372 } | 400 } |
373 | 401 |
374 } // namespace proxy | 402 } // namespace proxy |
375 } // namespace ppapi | 403 } // namespace ppapi |
OLD | NEW |