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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 explicit GLImageSync(const scoped_refptr<NativeImageBuffer>& buffer, | 30 explicit GLImageSync(const scoped_refptr<NativeImageBuffer>& buffer, |
31 const gfx::Size& size); | 31 const gfx::Size& size); |
32 | 32 |
33 // Implement GLImage. | 33 // Implement GLImage. |
34 void Destroy(bool have_context) override; | 34 void Destroy(bool have_context) override; |
35 gfx::Size GetSize() override; | 35 gfx::Size GetSize() override; |
36 unsigned GetInternalFormat() override; | 36 unsigned GetInternalFormat() override; |
37 bool BindTexImage(unsigned target) override; | 37 bool BindTexImage(unsigned target) override; |
38 void ReleaseTexImage(unsigned target) override; | 38 void ReleaseTexImage(unsigned target) override; |
| 39 bool CopyTexImage(unsigned target) override; |
39 bool CopyTexSubImage(unsigned target, | 40 bool CopyTexSubImage(unsigned target, |
40 const gfx::Point& offset, | 41 const gfx::Point& offset, |
41 const gfx::Rect& rect) override; | 42 const gfx::Rect& rect) override; |
42 void WillUseTexImage() override; | |
43 void WillModifyTexImage() override; | |
44 void DidModifyTexImage() override; | |
45 void DidUseTexImage() override; | |
46 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 43 bool ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
47 int z_order, | 44 int z_order, |
48 gfx::OverlayTransform transform, | 45 gfx::OverlayTransform transform, |
49 const gfx::Rect& bounds_rect, | 46 const gfx::Rect& bounds_rect, |
50 const gfx::RectF& crop_rect) override; | 47 const gfx::RectF& crop_rect) override; |
51 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 48 void OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
52 uint64_t process_tracing_id, | 49 uint64_t process_tracing_id, |
53 const std::string& dump_name) override; | 50 const std::string& dump_name) override; |
54 | 51 |
55 protected: | 52 protected: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 84 |
88 bool GLImageSync::BindTexImage(unsigned target) { | 85 bool GLImageSync::BindTexImage(unsigned target) { |
89 NOTREACHED(); | 86 NOTREACHED(); |
90 return false; | 87 return false; |
91 } | 88 } |
92 | 89 |
93 void GLImageSync::ReleaseTexImage(unsigned target) { | 90 void GLImageSync::ReleaseTexImage(unsigned target) { |
94 NOTREACHED(); | 91 NOTREACHED(); |
95 } | 92 } |
96 | 93 |
| 94 bool GLImageSync::CopyTexImage(unsigned target) { |
| 95 return false; |
| 96 } |
| 97 |
97 bool GLImageSync::CopyTexSubImage(unsigned target, | 98 bool GLImageSync::CopyTexSubImage(unsigned target, |
98 const gfx::Point& offset, | 99 const gfx::Point& offset, |
99 const gfx::Rect& rect) { | 100 const gfx::Rect& rect) { |
100 return false; | 101 return false; |
101 } | 102 } |
102 | 103 |
103 void GLImageSync::WillUseTexImage() { | |
104 } | |
105 | |
106 void GLImageSync::DidUseTexImage() { | |
107 } | |
108 | |
109 void GLImageSync::WillModifyTexImage() { | |
110 } | |
111 | |
112 void GLImageSync::DidModifyTexImage() { | |
113 } | |
114 | |
115 bool GLImageSync::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, | 104 bool GLImageSync::ScheduleOverlayPlane(gfx::AcceleratedWidget widget, |
116 int z_order, | 105 int z_order, |
117 gfx::OverlayTransform transform, | 106 gfx::OverlayTransform transform, |
118 const gfx::Rect& bounds_rect, | 107 const gfx::Rect& bounds_rect, |
119 const gfx::RectF& crop_rect) { | 108 const gfx::RectF& crop_rect) { |
120 NOTREACHED(); | 109 NOTREACHED(); |
121 return false; | 110 return false; |
122 } | 111 } |
123 | 112 |
124 void GLImageSync::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, | 113 void GLImageSync::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd, |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); | 339 image_buffer_ = NativeImageBuffer::Create(texture->service_id()); |
351 DCHECK(image_buffer_.get()); | 340 DCHECK(image_buffer_.get()); |
352 } | 341 } |
353 | 342 |
354 const Texture::FaceInfo& first_face = texture->face_infos_[0]; | 343 const Texture::FaceInfo& first_face = texture->face_infos_[0]; |
355 if (image_buffer_.get()) { | 344 if (image_buffer_.get()) { |
356 scoped_refptr<gfx::GLImage> gl_image( | 345 scoped_refptr<gfx::GLImage> gl_image( |
357 new GLImageSync(image_buffer_, | 346 new GLImageSync(image_buffer_, |
358 gfx::Size(first_face.level_infos[0].width, | 347 gfx::Size(first_face.level_infos[0].width, |
359 first_face.level_infos[0].height))); | 348 first_face.level_infos[0].height))); |
360 texture->SetLevelImage(NULL, target_, 0, gl_image.get()); | 349 texture->SetLevelImage(target_, 0, gl_image.get(), Texture::BOUND); |
361 } | 350 } |
362 | 351 |
363 const Texture::LevelInfo& level = first_face.level_infos[0]; | 352 const Texture::LevelInfo& level = first_face.level_infos[0]; |
364 level_info_ = LevelInfo(level.target, level.internal_format, level.width, | 353 level_info_ = LevelInfo(level.target, level.internal_format, level.width, |
365 level.height, level.depth, level.border, level.format, | 354 level.height, level.depth, level.border, level.format, |
366 level.type, level.cleared_rect); | 355 level.type, level.cleared_rect); |
367 } | 356 } |
368 | 357 |
369 TextureDefinition::~TextureDefinition() { | 358 TextureDefinition::~TextureDefinition() { |
370 } | 359 } |
371 | 360 |
372 Texture* TextureDefinition::CreateTexture() const { | 361 Texture* TextureDefinition::CreateTexture() const { |
373 GLuint texture_id; | 362 GLuint texture_id; |
374 glGenTextures(1, &texture_id); | 363 glGenTextures(1, &texture_id); |
375 | 364 |
376 Texture* texture(new Texture(texture_id)); | 365 Texture* texture(new Texture(texture_id)); |
377 UpdateTextureInternal(texture); | 366 UpdateTextureInternal(texture); |
378 | 367 |
379 return texture; | 368 return texture; |
380 } | 369 } |
381 | 370 |
382 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { | 371 void TextureDefinition::UpdateTextureInternal(Texture* texture) const { |
383 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); | 372 gfx::ScopedTextureBinder texture_binder(target_, texture->service_id()); |
384 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); | 373 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, min_filter_); |
385 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); | 374 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, mag_filter_); |
386 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); | 375 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap_s_); |
387 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); | 376 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap_t_); |
388 | 377 |
389 if (image_buffer_.get()) { | 378 if (image_buffer_.get()) { |
390 gfx::GLImage* existing_image = texture->GetLevelImage(target_, 0); | 379 gfx::GLImage* existing_image = texture->GetLevelImage(target_, 0, nullptr); |
391 // Don't need to re-bind if already bound before. | 380 // Don't need to re-bind if already bound before. |
392 if (!existing_image || !image_buffer_->IsClient(existing_image)) { | 381 if (!existing_image || !image_buffer_->IsClient(existing_image)) { |
393 image_buffer_->BindToTexture(target_); | 382 image_buffer_->BindToTexture(target_); |
394 } | 383 } |
395 } | 384 } |
396 | 385 |
397 if (defined_) { | 386 if (defined_) { |
398 texture->face_infos_.resize(1); | 387 texture->face_infos_.resize(1); |
399 texture->face_infos_[0].level_infos.resize(1); | 388 texture->face_infos_[0].level_infos.resize(1); |
400 texture->SetLevelInfo(NULL, level_info_.target, 0, | 389 texture->SetLevelInfo(NULL, level_info_.target, 0, |
401 level_info_.internal_format, level_info_.width, | 390 level_info_.internal_format, level_info_.width, |
402 level_info_.height, level_info_.depth, | 391 level_info_.height, level_info_.depth, |
403 level_info_.border, level_info_.format, | 392 level_info_.border, level_info_.format, |
404 level_info_.type, level_info_.cleared_rect); | 393 level_info_.type, level_info_.cleared_rect); |
405 } | 394 } |
406 | 395 |
407 if (image_buffer_.get()) { | 396 if (image_buffer_.get()) { |
408 texture->SetLevelImage( | 397 texture->SetLevelImage( |
409 NULL, | 398 target_, 0, |
410 target_, | 399 new GLImageSync(image_buffer_, |
411 0, | 400 gfx::Size(level_info_.width, level_info_.height)), |
412 new GLImageSync( | 401 Texture::BOUND); |
413 image_buffer_, | |
414 gfx::Size(level_info_.width, level_info_.height))); | |
415 } | 402 } |
416 | 403 |
417 texture->target_ = target_; | 404 texture->target_ = target_; |
418 texture->SetImmutable(immutable_); | 405 texture->SetImmutable(immutable_); |
419 texture->min_filter_ = min_filter_; | 406 texture->min_filter_ = min_filter_; |
420 texture->mag_filter_ = mag_filter_; | 407 texture->mag_filter_ = mag_filter_; |
421 texture->wrap_s_ = wrap_s_; | 408 texture->wrap_s_ = wrap_s_; |
422 texture->wrap_t_ = wrap_t_; | 409 texture->wrap_t_ = wrap_t_; |
423 texture->usage_ = usage_; | 410 texture->usage_ = usage_; |
424 } | 411 } |
425 | 412 |
426 void TextureDefinition::UpdateTexture(Texture* texture) const { | 413 void TextureDefinition::UpdateTexture(Texture* texture) const { |
427 GLuint old_service_id = 0u; | 414 GLuint old_service_id = 0u; |
428 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { | 415 if (image_buffer_.get() && g_avoid_egl_target_texture_reuse) { |
429 GLuint service_id = 0u; | 416 GLuint service_id = 0u; |
430 glGenTextures(1, &service_id); | 417 glGenTextures(1, &service_id); |
431 old_service_id = texture->service_id(); | 418 old_service_id = texture->service_id(); |
432 texture->SetServiceId(service_id); | 419 texture->SetServiceId(service_id); |
433 | 420 |
434 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); | 421 DCHECK_EQ(static_cast<GLenum>(GL_TEXTURE_2D), target_); |
435 GLint bound_id = 0; | 422 GLint bound_id = 0; |
436 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); | 423 glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_id); |
437 if (bound_id == static_cast<GLint>(old_service_id)) { | 424 if (bound_id == static_cast<GLint>(old_service_id)) { |
438 glBindTexture(target_, service_id); | 425 glBindTexture(target_, service_id); |
439 } | 426 } |
440 texture->SetLevelImage(NULL, target_, 0, NULL); | 427 texture->SetLevelImage(target_, 0, NULL, Texture::UNBOUND); |
441 } | 428 } |
442 | 429 |
443 UpdateTextureInternal(texture); | 430 UpdateTextureInternal(texture); |
444 | 431 |
445 if (old_service_id) { | 432 if (old_service_id) { |
446 glDeleteTextures(1, &old_service_id); | 433 glDeleteTextures(1, &old_service_id); |
447 } | 434 } |
448 } | 435 } |
449 | 436 |
450 bool TextureDefinition::Matches(const Texture* texture) const { | 437 bool TextureDefinition::Matches(const Texture* texture) const { |
451 DCHECK(target_ == texture->target()); | 438 DCHECK(target_ == texture->target()); |
452 if (texture->min_filter_ != min_filter_ || | 439 if (texture->min_filter_ != min_filter_ || |
453 texture->mag_filter_ != mag_filter_ || | 440 texture->mag_filter_ != mag_filter_ || |
454 texture->wrap_s_ != wrap_s_ || | 441 texture->wrap_s_ != wrap_s_ || |
455 texture->wrap_t_ != wrap_t_ || | 442 texture->wrap_t_ != wrap_t_ || |
456 texture->SafeToRenderFrom() != SafeToRenderFrom()) { | 443 texture->SafeToRenderFrom() != SafeToRenderFrom()) { |
457 return false; | 444 return false; |
458 } | 445 } |
459 | 446 |
460 // Texture became defined. | 447 // Texture became defined. |
461 if (!image_buffer_.get() && texture->IsDefined()) | 448 if (!image_buffer_.get() && texture->IsDefined()) |
462 return false; | 449 return false; |
463 | 450 |
464 // All structural changes should have orphaned the texture. | 451 // All structural changes should have orphaned the texture. |
465 if (image_buffer_.get() && !texture->GetLevelImage(texture->target(), 0)) | 452 if (image_buffer_.get() && |
| 453 !texture->GetLevelImage(texture->target(), 0, nullptr)) { |
466 return false; | 454 return false; |
| 455 } |
467 | 456 |
468 return true; | 457 return true; |
469 } | 458 } |
470 | 459 |
471 bool TextureDefinition::SafeToRenderFrom() const { | 460 bool TextureDefinition::SafeToRenderFrom() const { |
472 return level_info_.cleared_rect.Contains( | 461 return level_info_.cleared_rect.Contains( |
473 gfx::Rect(level_info_.width, level_info_.height)); | 462 gfx::Rect(level_info_.width, level_info_.height)); |
474 } | 463 } |
475 | 464 |
476 } // namespace gles2 | 465 } // namespace gles2 |
477 } // namespace gpu | 466 } // namespace gpu |
OLD | NEW |