| 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "gpu/GLES2/gl2extchromium.h" | 10 #include "gpu/GLES2/gl2extchromium.h" |
| 11 #include "gpu/command_buffer/client/gles2_implementation.h" | 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 12 #include "gpu/command_buffer/common/mailbox.h" | 12 #include "gpu/command_buffer/common/mailbox.h" |
| 13 #include "gpu/command_buffer/common/sync_token.h" |
| 13 #include "ppapi/proxy/compositor_resource.h" | 14 #include "ppapi/proxy/compositor_resource.h" |
| 14 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" | 15 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
| 15 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
| 16 #include "ppapi/thunk/ppb_graphics_3d_api.h" | 17 #include "ppapi/thunk/ppb_graphics_3d_api.h" |
| 17 #include "ppapi/thunk/ppb_image_data_api.h" | 18 #include "ppapi/thunk/ppb_image_data_api.h" |
| 18 | 19 |
| 19 using gpu::gles2::GLES2Implementation; | 20 using gpu::gles2::GLES2Implementation; |
| 20 using ppapi::thunk::EnterResourceNoLock; | 21 using ppapi::thunk::EnterResourceNoLock; |
| 21 using ppapi::thunk::PPB_ImageData_API; | 22 using ppapi::thunk::PPB_ImageData_API; |
| 22 using ppapi::thunk::PPB_Graphics3D_API; | 23 using ppapi::thunk::PPB_Graphics3D_API; |
| 23 | 24 |
| 24 namespace ppapi { | 25 namespace ppapi { |
| 25 namespace proxy { | 26 namespace proxy { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 float clamp(float value) { | 30 float clamp(float value) { |
| 30 return std::min(std::max(value, 0.0f), 1.0f); | 31 return std::min(std::max(value, 0.0f), 1.0f); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void OnTextureReleased( | 34 void OnTextureReleased(const ScopedPPResource& layer, |
| 34 const ScopedPPResource& layer, | 35 const ScopedPPResource& context, |
| 35 const ScopedPPResource& context, | 36 uint32_t texture, |
| 36 uint32_t texture, | 37 const scoped_refptr<TrackedCallback>& release_callback, |
| 37 const scoped_refptr<TrackedCallback>& release_callback, | 38 int32_t result, |
| 38 int32_t result, | 39 const gpu::SyncToken& sync_token, |
| 39 uint32_t sync_point, | 40 bool is_lost) { |
| 40 bool is_lost) { | |
| 41 if (!TrackedCallback::IsPending(release_callback)) | 41 if (!TrackedCallback::IsPending(release_callback)) |
| 42 return; | 42 return; |
| 43 | 43 |
| 44 if (result != PP_OK) { | 44 if (result != PP_OK) { |
| 45 release_callback->Run(result); | 45 release_callback->Run(result); |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 | 48 |
| 49 do { | 49 do { |
| 50 if (!sync_point) | 50 if (!sync_token.HasData()) |
| 51 break; | 51 break; |
| 52 | 52 |
| 53 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); | 53 EnterResourceNoLock<PPB_Graphics3D_API> enter(context.get(), true); |
| 54 if (enter.failed()) | 54 if (enter.failed()) |
| 55 break; | 55 break; |
| 56 | 56 |
| 57 PPB_Graphics3D_Shared* graphics = | 57 PPB_Graphics3D_Shared* graphics = |
| 58 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 58 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 59 | 59 |
| 60 GLES2Implementation* gl = graphics->gles2_impl(); | 60 GLES2Implementation* gl = graphics->gles2_impl(); |
| 61 gl->WaitSyncPointCHROMIUM(sync_point); | 61 gl->WaitSyncTokenCHROMIUM(sync_token.GetConstData()); |
| 62 } while (false); | 62 } while (false); |
| 63 | 63 |
| 64 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); | 64 release_callback->Run(is_lost ? PP_ERROR_FAILED : PP_OK); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void OnImageReleased( | 67 void OnImageReleased(const ScopedPPResource& layer, |
| 68 const ScopedPPResource& layer, | 68 const ScopedPPResource& image, |
| 69 const ScopedPPResource& image, | 69 const scoped_refptr<TrackedCallback>& release_callback, |
| 70 const scoped_refptr<TrackedCallback>& release_callback, | 70 int32_t result, |
| 71 int32_t result, | 71 const gpu::SyncToken& sync_token, |
| 72 uint32_t sync_point, | 72 bool is_lost) { |
| 73 bool is_lost) { | |
| 74 if (!TrackedCallback::IsPending(release_callback)) | 73 if (!TrackedCallback::IsPending(release_callback)) |
| 75 return; | 74 return; |
| 76 release_callback->Run(result); | 75 release_callback->Run(result); |
| 77 } | 76 } |
| 78 | 77 |
| 79 } // namespace | 78 } // namespace |
| 80 | 79 |
| 81 CompositorLayerResource::CompositorLayerResource( | 80 CompositorLayerResource::CompositorLayerResource( |
| 82 Connection connection, | 81 Connection connection, |
| 83 PP_Instance instance, | 82 PP_Instance instance, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 texture, target, | 167 texture, target, |
| 169 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); | 168 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); |
| 170 | 169 |
| 171 // Set the source size to (1, 1). It will be used to verify the source_rect | 170 // Set the source size to (1, 1). It will be used to verify the source_rect |
| 172 // passed to SetSourceRect(). | 171 // passed to SetSourceRect(). |
| 173 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); | 172 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); |
| 174 | 173 |
| 175 data_.common.size = *size; | 174 data_.common.size = *size; |
| 176 data_.common.resource_id = compositor_->GenerateResourceId(); | 175 data_.common.resource_id = compositor_->GenerateResourceId(); |
| 177 data_.texture->target = target; | 176 data_.texture->target = target; |
| 178 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); | 177 data_.texture->sync_token = gpu::SyncToken(gl->InsertSyncPointCHROMIUM()); |
| 179 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 178 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
| 180 data_.texture->source_rect.size = source_size_; | 179 data_.texture->source_rect.size = source_size_; |
| 181 | 180 |
| 182 // If the PP_Resource of this layer is released by the plugin, the | 181 // If the PP_Resource of this layer is released by the plugin, the |
| 183 // release_callback will be aborted immediately, but the texture or image | 182 // release_callback will be aborted immediately, but the texture or image |
| 184 // in this layer may still being used by chromium compositor. So we have to | 183 // in this layer may still being used by chromium compositor. So we have to |
| 185 // use ScopedPPResource to keep this resource alive until the texture or image | 184 // use ScopedPPResource to keep this resource alive until the texture or image |
| 186 // is released by the chromium compositor. | 185 // is released by the chromium compositor. |
| 187 release_callback_ = base::Bind( | 186 release_callback_ = base::Bind( |
| 188 &OnTextureReleased, | 187 &OnTextureReleased, |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 378 |
| 380 // Do not allow using a block callback as a release callback. | 379 // Do not allow using a block callback as a release callback. |
| 381 if (release_callback->is_blocking()) | 380 if (release_callback->is_blocking()) |
| 382 return PP_ERROR_BADARGUMENT; | 381 return PP_ERROR_BADARGUMENT; |
| 383 | 382 |
| 384 return PP_OK; | 383 return PP_OK; |
| 385 } | 384 } |
| 386 | 385 |
| 387 } // namespace proxy | 386 } // namespace proxy |
| 388 } // namespace ppapi | 387 } // namespace ppapi |
| OLD | NEW |