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" |
11 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" | 11 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
12 #include "ppapi/thunk/enter.h" | 12 #include "ppapi/thunk/enter.h" |
13 #include "ppapi/thunk/ppb_graphics_3d_api.h" | 13 #include "ppapi/thunk/ppb_graphics_3d_api.h" |
14 #include "ppapi/thunk/ppb_image_data_api.h" | 14 #include "ppapi/thunk/ppb_image_data_api.h" |
15 | 15 |
16 using gpu::gles2::GLES2Implementation; | 16 using gpu::gles2::GLES2Implementation; |
17 using ppapi::thunk::EnterResourceNoLock; | 17 using ppapi::thunk::EnterResourceNoLock; |
18 using ppapi::thunk::PPB_ImageData_API; | 18 using ppapi::thunk::PPB_ImageData_API; |
19 using ppapi::thunk::PPB_Graphics3D_API; | 19 using ppapi::thunk::PPB_Graphics3D_API; |
20 | 20 |
21 namespace ppapi { | 21 namespace ppapi { |
22 namespace proxy { | 22 namespace proxy { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class Scoped2DTextureBinder { | |
27 public: | |
28 Scoped2DTextureBinder(GLES2Implementation* gl, uint32_t id) | |
29 : gl_(gl), old_id_(-1) { | |
30 gl_->GetIntegerv(GL_TEXTURE_BINDING_2D, &old_id_); | |
31 gl_->BindTexture(GL_TEXTURE_2D, id); | |
32 } | |
33 | |
34 ~Scoped2DTextureBinder() { | |
35 gl_->BindTexture(GL_TEXTURE_2D, old_id_); | |
36 } | |
37 | |
38 private: | |
39 GLES2Implementation* gl_; | |
40 int32_t old_id_; | |
41 }; | |
42 | |
43 float clamp(float value) { | 26 float clamp(float value) { |
44 return std::min(std::max(value, 0.0f), 1.0f); | 27 return std::min(std::max(value, 0.0f), 1.0f); |
45 } | 28 } |
46 | 29 |
47 void OnTextureReleased( | 30 void OnTextureReleased( |
48 const ScopedPPResource& layer, | 31 const ScopedPPResource& layer, |
49 const ScopedPPResource& context, | 32 const ScopedPPResource& context, |
50 uint32_t texture, | 33 uint32_t texture, |
51 const scoped_refptr<TrackedCallback>& release_callback, | 34 const scoped_refptr<TrackedCallback>& release_callback, |
52 uint32_t sync_point, | 35 uint32_t sync_point, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (enter.failed()) | 129 if (enter.failed()) |
147 return PP_ERROR_BADRESOURCE; | 130 return PP_ERROR_BADRESOURCE; |
148 | 131 |
149 if (!size || size->width <= 0 || size->height <= 0) | 132 if (!size || size->width <= 0 || size->height <= 0) |
150 return PP_ERROR_BADARGUMENT; | 133 return PP_ERROR_BADARGUMENT; |
151 | 134 |
152 PPB_Graphics3D_Shared* graphics = | 135 PPB_Graphics3D_Shared* graphics = |
153 static_cast<PPB_Graphics3D_Shared*>(enter.object()); | 136 static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
154 | 137 |
155 GLES2Implementation* gl = graphics->gles2_impl(); | 138 GLES2Implementation* gl = graphics->gles2_impl(); |
156 Scoped2DTextureBinder scoped_2d_texture_binder(gl, texture); | |
157 | 139 |
158 // Generate a Mailbox for the texture. | 140 // Generate a Mailbox for the texture. |
159 gl->GenMailboxCHROMIUM( | 141 gl->GenMailboxCHROMIUM( |
160 reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); | 142 reinterpret_cast<GLbyte*>(data_.texture->mailbox.name)); |
161 gl->ProduceTextureCHROMIUM( | 143 gl->ProduceTextureDirectCHROMIUM( |
162 GL_TEXTURE_2D, | 144 texture, GL_TEXTURE_2D, |
163 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); | 145 reinterpret_cast<const GLbyte*>(data_.texture->mailbox.name)); |
164 | 146 |
165 // Set the source size to (1, 1). It will be used to verify the source_rect | 147 // Set the source size to (1, 1). It will be used to verify the source_rect |
166 // passed to SetSourceRect(). | 148 // passed to SetSourceRect(). |
167 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); | 149 source_size_ = PP_MakeFloatSize(1.0f, 1.0f); |
168 | 150 |
169 data_.common.size = *size; | 151 data_.common.size = *size; |
170 data_.common.resource_id = compositor_->GenerateResourceId(); | 152 data_.common.resource_id = compositor_->GenerateResourceId(); |
171 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); | 153 data_.texture->sync_point = gl->InsertSyncPointCHROMIUM(); |
172 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); | 154 data_.texture->source_rect.point = PP_MakeFloatPoint(0.0f, 0.0f); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 348 |
367 // Do not allow using a block callback as a release callback. | 349 // Do not allow using a block callback as a release callback. |
368 if (release_callback->is_blocking()) | 350 if (release_callback->is_blocking()) |
369 return PP_ERROR_BADARGUMENT; | 351 return PP_ERROR_BADARGUMENT; |
370 | 352 |
371 return PP_OK; | 353 return PP_OK; |
372 } | 354 } |
373 | 355 |
374 } // namespace proxy | 356 } // namespace proxy |
375 } // namespace ppapi | 357 } // namespace ppapi |
OLD | NEW |