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 "gpu/command_buffer/service/texture_definition.h" | 5 #include "gpu/command_buffer/service/texture_definition.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 private: | 236 private: |
237 ~NativeImageBufferStub() override {} | 237 ~NativeImageBufferStub() override {} |
238 void AddClient(gfx::GLImage* client) override {} | 238 void AddClient(gfx::GLImage* client) override {} |
239 void RemoveClient(gfx::GLImage* client) override {} | 239 void RemoveClient(gfx::GLImage* client) override {} |
240 bool IsClient(gfx::GLImage* client) override { return true; } | 240 bool IsClient(gfx::GLImage* client) override { return true; } |
241 void BindToTexture(GLenum target) override {} | 241 void BindToTexture(GLenum target) override {} |
242 | 242 |
243 DISALLOW_COPY_AND_ASSIGN(NativeImageBufferStub); | 243 DISALLOW_COPY_AND_ASSIGN(NativeImageBufferStub); |
244 }; | 244 }; |
245 | 245 |
246 bool g_avoid_egl_target_texture_reuse = false; | |
247 | |
246 } // anonymous namespace | 248 } // anonymous namespace |
247 | 249 |
248 // static | 250 // static |
249 scoped_refptr<NativeImageBuffer> NativeImageBuffer::Create(GLuint texture_id) { | 251 scoped_refptr<NativeImageBuffer> NativeImageBuffer::Create(GLuint texture_id) { |
250 switch (gfx::GetGLImplementation()) { | 252 switch (gfx::GetGLImplementation()) { |
251 #if !defined(OS_MACOSX) | 253 #if !defined(OS_MACOSX) |
252 case gfx::kGLImplementationEGLGLES2: | 254 case gfx::kGLImplementationEGLGLES2: |
253 return NativeImageBufferEGL::Create(texture_id); | 255 return NativeImageBufferEGL::Create(texture_id); |
254 #endif | 256 #endif |
255 case gfx::kGLImplementationMockGL: | 257 case gfx::kGLImplementationMockGL: |
256 return new NativeImageBufferStub; | 258 return new NativeImageBufferStub; |
257 default: | 259 default: |
258 NOTREACHED(); | 260 NOTREACHED(); |
259 return NULL; | 261 return NULL; |
260 } | 262 } |
261 } | 263 } |
262 | 264 |
265 // static | |
266 void TextureDefinition::AvoidEGLTargetTextureReuse() { | |
267 g_avoid_egl_target_texture_reuse = true; | |
268 } | |
269 | |
263 TextureDefinition::LevelInfo::LevelInfo() | 270 TextureDefinition::LevelInfo::LevelInfo() |
264 : target(0), | 271 : target(0), |
265 internal_format(0), | 272 internal_format(0), |
266 width(0), | 273 width(0), |
267 height(0), | 274 height(0), |
268 depth(0), | 275 depth(0), |
269 border(0), | 276 border(0), |
270 format(0), | 277 format(0), |
271 type(0), | 278 type(0), |
272 cleared(false) { | 279 cleared(false) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 } | 347 } |
341 | 348 |
342 TextureDefinition::~TextureDefinition() { | 349 TextureDefinition::~TextureDefinition() { |
343 } | 350 } |
344 | 351 |
345 Texture* TextureDefinition::CreateTexture() const { | 352 Texture* TextureDefinition::CreateTexture() const { |
346 GLuint texture_id; | 353 GLuint texture_id; |
347 glGenTextures(1, &texture_id); | 354 glGenTextures(1, &texture_id); |
348 | 355 |
349 Texture* texture(new Texture(texture_id)); | 356 Texture* texture(new Texture(texture_id)); |
350 UpdateTexture(texture); | 357 UpdateTextureInternal(texture); |
351 | 358 |
352 return texture; | 359 return texture; |
353 } | 360 } |
354 | 361 |
355 void TextureDefinition::UpdateTexture(Texture* texture) const { | 362 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { |
356 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); | 363 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); |
357 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); | 364 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); |
358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); | 365 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); |
359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); | 366 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); |
360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); | 367 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); |
361 if (image_buffer_.get()) | 368 if (image_buffer_.get()) |
362 image_buffer_->BindToTexture(target_); | 369 image_buffer_->BindToTexture(target_); |
363 // We have to make sure the changes are visible to other clients in this share | 370 // We have to make sure the changes are visible to other clients in this share |
364 // group. As far as the clients are concerned, the mailbox semantics only | 371 // group. As far as the clients are concerned, the mailbox semantics only |
365 // demand a single flush from the client after changes are first made, | 372 // demand a single flush from the client after changes are first made, |
(...skipping 24 matching lines...) Expand all Loading... | |
390 | 397 |
391 texture->target_ = target_; | 398 texture->target_ = target_; |
392 texture->SetImmutable(immutable_); | 399 texture->SetImmutable(immutable_); |
393 texture->min_filter_ = min_filter_; | 400 texture->min_filter_ = min_filter_; |
394 texture->mag_filter_ = mag_filter_; | 401 texture->mag_filter_ = mag_filter_; |
395 texture->wrap_s_ = wrap_s_; | 402 texture->wrap_s_ = wrap_s_; |
396 texture->wrap_t_ = wrap_t_; | 403 texture->wrap_t_ = wrap_t_; |
397 texture->usage_ = usage_; | 404 texture->usage_ = usage_; |
398 } | 405 } |
399 | 406 |
407 void TextureDefinition::UpdateTexture(Texture* texture) const { | |
408 GLuint old_service_id = 0u; | |
409 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { | |
410 GLuint service_id = 0u; | |
411 glGenTextures(1, &service_id); | |
412 old_service_id = texture->service_id(); | |
413 texture->SetServiceId(service_id); | |
414 } | |
415 | |
no sievers
2015/04/29 17:21:30
Sorry I missed this though we talked about it - bu
boliu
2015/04/29 18:22:36
SG, I'll make the patch.
| |
416 UpdateTextureInternal(texture); | |
417 | |
418 if (old_service_id) { | |
419 glDeleteTextures(1, &old_service_id); | |
420 } | |
421 } | |
422 | |
400 bool TextureDefinition::Matches(const Texture* texture) const { | 423 bool TextureDefinition::Matches(const Texture* texture) const { |
401 DCHECK(target_ == texture->target()); | 424 DCHECK(target_ == texture->target()); |
402 if (texture->min_filter_ != min_filter_ || | 425 if (texture->min_filter_ != min_filter_ || |
403 texture->mag_filter_ != mag_filter_ || | 426 texture->mag_filter_ != mag_filter_ || |
404 texture->wrap_s_ != wrap_s_ || | 427 texture->wrap_s_ != wrap_s_ || |
405 texture->wrap_t_ != wrap_t_ || | 428 texture->wrap_t_ != wrap_t_ || |
406 texture->SafeToRenderFrom() != SafeToRenderFrom()) { | 429 texture->SafeToRenderFrom() != SafeToRenderFrom()) { |
407 return false; | 430 return false; |
408 } | 431 } |
409 | 432 |
410 // Texture became defined. | 433 // Texture became defined. |
411 if (!image_buffer_.get() && texture->IsDefined()) | 434 if (!image_buffer_.get() && texture->IsDefined()) |
412 return false; | 435 return false; |
413 | 436 |
414 // All structural changes should have orphaned the texture. | 437 // All structural changes should have orphaned the texture. |
415 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) | 438 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) |
416 return false; | 439 return false; |
417 | 440 |
418 return true; | 441 return true; |
419 } | 442 } |
420 | 443 |
421 bool TextureDefinition::SafeToRenderFrom() const { | 444 bool TextureDefinition::SafeToRenderFrom() const { |
422 return level_info_.cleared; | 445 return level_info_.cleared; |
423 } | 446 } |
424 | 447 |
425 } // namespace gles2 | 448 } // namespace gles2 |
426 } // namespace gpu | 449 } // namespace gpu |
OLD | NEW |