Chromium Code Reviews| Index: ppapi/proxy/compositor_layer_resource.cc |
| diff --git a/ppapi/proxy/compositor_layer_resource.cc b/ppapi/proxy/compositor_layer_resource.cc |
| index a33f7c17f2ac7ff631f9ce49342e4fe555edc630..b04f4e66cc2f20d7e1b6b2e730d4ef28780904e0 100644 |
| --- a/ppapi/proxy/compositor_layer_resource.cc |
| +++ b/ppapi/proxy/compositor_layer_resource.cc |
| @@ -28,6 +28,7 @@ float clamp(float value) { |
| } |
| void OnTextureReleased( |
| + const scoped_refptr<CompositorResource> compositor, |
| const ScopedPPResource& layer, |
| const ScopedPPResource& context, |
| uint32_t texture, |
| @@ -56,6 +57,7 @@ void OnTextureReleased( |
| } |
| void OnImageReleased( |
| + const scoped_refptr<CompositorResource> compositor, |
| const ScopedPPResource& layer, |
| const ScopedPPResource& image, |
| const scoped_refptr<TrackedCallback>& release_callback, |
| @@ -71,7 +73,7 @@ void OnImageReleased( |
| CompositorLayerResource::CompositorLayerResource( |
| Connection connection, |
| PP_Instance instance, |
| - const CompositorResource* compositor) |
| + scoped_refptr<CompositorResource> compositor) |
| : PluginResource(connection, instance), |
| compositor_(compositor), |
| source_size_(PP_MakeFloatSize(0.0f, 0.0f)) { |
| @@ -105,7 +107,6 @@ int32_t CompositorLayerResource::SetColor(float red, |
| if (!size) |
| return PP_ERROR_BADARGUMENT; |
| - |
| data_.color->red = clamp(red); |
| data_.color->green = clamp(green); |
| data_.color->blue = clamp(blue); |
| @@ -138,8 +139,22 @@ int32_t CompositorLayerResource::SetTexture( |
| GLES2Implementation* gl = graphics->gles2_impl(); |
| // Generate a Mailbox for the texture. |
| - gl->GenMailboxCHROMIUM( |
| - reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); |
| + // gl->GenMailboxCHROMIUM( |
| + // reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); |
| + // |
| + // TODO(penghuang): Use gl->GenMailboxCHROMIUM() when the bug in |
| + // 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.
|
| + static bool flag = false; |
| + if (!flag) { |
| + srand(time(NULL)); |
| + flag = true; |
| + } |
| + uint8_t value = 1; |
| + for (size_t i = 1; i < arraysize(data_.texture->mailbox.name); ++i) { |
| + data_.texture->mailbox.name[i] = static_cast<uint8_t>(rand()); |
| + value ^= data_.texture->mailbox.name[i]; |
| + } |
| + data_.texture->mailbox.name[0] = value; |
| gl->ProduceTextureDirectCHROMIUM( |
| texture, GL_TEXTURE_2D, |
| reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); |
| @@ -158,9 +173,12 @@ int32_t CompositorLayerResource::SetTexture( |
| // release_callback will be aborted immediately, but the texture or image |
| // in this layer may still being used by chromium compositor. So we have to |
| // use ScopedPPResource to keep this resource alive until the texture or image |
| - // is released by the chromium compositor. |
| + // is released by the chromium compositor. And we need keep the compositor |
| + // alive, otherwise we will not receive the release IPC message for the |
| + // texture. |
|
piman
2014/06/19 20:44:04
maybe you should let the plugin do that.
Peng
2014/06/19 22:33:41
Done.
|
| release_callback_ = base::Bind( |
| &OnTextureReleased, |
| + compositor_, // Keep compositor alive. |
| ScopedPPResource(pp_resource()), // Keep layer alive. |
| ScopedPPResource(context), // Keep context alive |
| texture, |
| @@ -207,8 +225,15 @@ int32_t CompositorLayerResource::SetImage( |
| data_.image->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
| data_.image->source_rect.size = source_size_; |
| + // If the PP_Resource of this layer is released by the plugin, the |
| + // release_callback will be aborted immediately, but the texture or image |
| + // in this layer may still being used by chromium compositor. So we have to |
| + // use ScopedPPResource to keep this resource alive until the texture or image |
| + // is released by the chromium compositor. And we need keep the compositor |
| + // alive, otherwise we will not receive the release IPC message for the image. |
| release_callback_ = base::Bind( |
| &OnImageReleased, |
| + compositor_, // Keep compositor alive. |
| ScopedPPResource(pp_resource()), // Keep layer alive. |
| ScopedPPResource(image_data), // Keep image_data alive. |
| release_callback); |
| @@ -333,7 +358,7 @@ bool CompositorLayerResource::SetType(LayerType type) { |
| int32_t CompositorLayerResource::CheckForSetTextureAndImage( |
| LayerType type, |
| const scoped_refptr<TrackedCallback>& release_callback) { |
| - if (!compositor_) |
| + if (!compositor_) |
| return PP_ERROR_BADRESOURCE; |
| if (compositor_->IsInProgress()) |