OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/exo/buffer.h" | 5 #include "components/exo/buffer.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | |
12 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <utility> |
13 | 13 |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "base/trace_event/trace_event_argument.h" | 17 #include "base/trace_event/trace_event_argument.h" |
18 #include "cc/output/context_provider.h" | 18 #include "cc/output/context_provider.h" |
19 #include "cc/resources/single_release_callback.h" | 19 #include "cc/resources/single_release_callback.h" |
20 #include "cc/resources/texture_mailbox.h" | 20 #include "cc/resources/texture_mailbox.h" |
21 #include "gpu/command_buffer/client/gles2_interface.h" | 21 #include "gpu/command_buffer/client/gles2_interface.h" |
22 #include "ui/aura/env.h" | 22 #include "ui/aura/env.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 gles2->ActiveTexture(GL_TEXTURE0); | 147 gles2->ActiveTexture(GL_TEXTURE0); |
148 gles2->BindTexture(texture_target_, texture_id_); | 148 gles2->BindTexture(texture_target_, texture_id_); |
149 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); | 149 gles2->ReleaseTexImage2DCHROMIUM(texture_target_, image_id_); |
150 } | 150 } |
151 | 151 |
152 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
153 // Buffer, public: | 153 // Buffer, public: |
154 | 154 |
155 Buffer::Buffer(scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer, | 155 Buffer::Buffer(scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer, |
156 unsigned texture_target) | 156 unsigned texture_target) |
157 : gpu_memory_buffer_(gpu_memory_buffer.Pass()), | 157 : gpu_memory_buffer_(std::move(gpu_memory_buffer)), |
158 texture_target_(texture_target), | 158 texture_target_(texture_target), |
159 use_count_(0) {} | 159 use_count_(0) {} |
160 | 160 |
161 Buffer::~Buffer() {} | 161 Buffer::~Buffer() {} |
162 | 162 |
163 scoped_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( | 163 scoped_ptr<cc::SingleReleaseCallback> Buffer::ProduceTextureMailbox( |
164 cc::TextureMailbox* texture_mailbox) { | 164 cc::TextureMailbox* texture_mailbox) { |
165 DLOG_IF(WARNING, use_count_) | 165 DLOG_IF(WARNING, use_count_) |
166 << "Producing a texture mailbox for a buffer that has not been released"; | 166 << "Producing a texture mailbox for a buffer that has not been released"; |
167 | 167 |
168 // Increment the use count for this buffer. | 168 // Increment the use count for this buffer. |
169 ++use_count_; | 169 ++use_count_; |
170 | 170 |
171 // Creating a new texture is relatively expensive so we reuse the last | 171 // Creating a new texture is relatively expensive so we reuse the last |
172 // texture whenever possible. | 172 // texture whenever possible. |
173 scoped_ptr<Texture> texture = last_texture_.Pass(); | 173 scoped_ptr<Texture> texture = std::move(last_texture_); |
174 | 174 |
175 // If texture is lost, destroy it to ensure that we create a new one below. | 175 // If texture is lost, destroy it to ensure that we create a new one below. |
176 if (texture && texture->IsLost()) | 176 if (texture && texture->IsLost()) |
177 texture.reset(); | 177 texture.reset(); |
178 | 178 |
179 // Create a new texture if one doesn't already exist. The contents of this | 179 // Create a new texture if one doesn't already exist. The contents of this |
180 // buffer can be bound to the texture using a call to BindTexImage and must | 180 // buffer can be bound to the texture using a call to BindTexImage and must |
181 // be released using a matching ReleaseTexImage call before it can be reused | 181 // be released using a matching ReleaseTexImage call before it can be reused |
182 // or destroyed. | 182 // or destroyed. |
183 if (!texture) { | 183 if (!texture) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 // Release image so it can safely be reused or destroyed. | 244 // Release image so it can safely be reused or destroyed. |
245 texture->ReleaseTexImage(sync_token); | 245 texture->ReleaseTexImage(sync_token); |
246 | 246 |
247 // Early out if buffer is gone. This can happen when the client destroyed the | 247 // Early out if buffer is gone. This can happen when the client destroyed the |
248 // buffer before receiving a release callback. | 248 // buffer before receiving a release callback. |
249 if (!buffer) | 249 if (!buffer) |
250 return; | 250 return; |
251 | 251 |
252 // Allow buffer to reused texture if it's not lost. | 252 // Allow buffer to reused texture if it's not lost. |
253 if (!is_lost) | 253 if (!is_lost) |
254 buffer->last_texture_ = texture.Pass(); | 254 buffer->last_texture_ = std::move(texture); |
255 | 255 |
256 buffer->Release(); | 256 buffer->Release(); |
257 } | 257 } |
258 | 258 |
259 } // namespace exo | 259 } // namespace exo |
OLD | NEW |