OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_manager.h" | 5 #include "gpu/command_buffer/service/texture_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 UpdateCleared(); | 997 UpdateCleared(); |
998 UpdateCanRenderCondition(); | 998 UpdateCanRenderCondition(); |
999 UpdateHasImages(); | 999 UpdateHasImages(); |
1000 if (IsAttachedToFramebuffer()) { | 1000 if (IsAttachedToFramebuffer()) { |
1001 // TODO(gman): If textures tracked which framebuffers they were attached to | 1001 // TODO(gman): If textures tracked which framebuffers they were attached to |
1002 // we could just mark those framebuffers as not complete. | 1002 // we could just mark those framebuffers as not complete. |
1003 IncAllFramebufferStateChangeCount(); | 1003 IncAllFramebufferStateChangeCount(); |
1004 } | 1004 } |
1005 } | 1005 } |
1006 | 1006 |
| 1007 void Texture::SetStreamTextureServiceId(GLuint service_id) { |
| 1008 GLuint new_service_id = service_id ? service_id : owned_service_id_; |
| 1009 |
| 1010 // Take no action if this isn't an OES_EXTERNAL texture. |
| 1011 if (target_ && target_ != GL_TEXTURE_EXTERNAL_OES) |
| 1012 return; |
| 1013 |
| 1014 if (service_id_ != new_service_id) { |
| 1015 service_id_ = new_service_id; |
| 1016 IncrementManagerServiceIdGeneration(); |
| 1017 if (gl::GLContext* context = gl::GLContext::GetCurrent()) { |
| 1018 // It would be preferable to pass in the decoder, and ask it to do this |
| 1019 // instead. However, there are several cases, such as TextureDefinition, |
| 1020 // that show up without a clear context owner. So, instead, we use the |
| 1021 // current state's state restorer. |
| 1022 if (gl::GLStateRestorer* restorer = context->GetGLStateRestorer()) |
| 1023 restorer->RestoreAllExternalTextureBindingsIfNeeded(); |
| 1024 } |
| 1025 } |
| 1026 } |
| 1027 |
1007 void Texture::MarkLevelAsInternalWorkaround(GLenum target, GLint level) { | 1028 void Texture::MarkLevelAsInternalWorkaround(GLenum target, GLint level) { |
1008 DCHECK_GE(level, 0); | 1029 DCHECK_GE(level, 0); |
1009 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1030 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1010 DCHECK_LT(static_cast<size_t>(face_index), | 1031 DCHECK_LT(static_cast<size_t>(face_index), |
1011 face_infos_.size()); | 1032 face_infos_.size()); |
1012 DCHECK_LT(static_cast<size_t>(level), | 1033 DCHECK_LT(static_cast<size_t>(level), |
1013 face_infos_[face_index].level_infos.size()); | 1034 face_infos_[face_index].level_infos.size()); |
1014 Texture::LevelInfo& info = | 1035 Texture::LevelInfo& info = |
1015 face_infos_[face_index].level_infos[level]; | 1036 face_infos_[face_index].level_infos[level]; |
1016 info.internal_workaround = true; | 1037 info.internal_workaround = true; |
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 UpdateMipCleared(&info, info.width, info.height, | 1491 UpdateMipCleared(&info, info.width, info.height, |
1471 gfx::Rect(info.width, info.height)); | 1492 gfx::Rect(info.width, info.height)); |
1472 return true; | 1493 return true; |
1473 } | 1494 } |
1474 | 1495 |
1475 void Texture::SetLevelImageInternal(GLenum target, | 1496 void Texture::SetLevelImageInternal(GLenum target, |
1476 GLint level, | 1497 GLint level, |
1477 gl::GLImage* image, | 1498 gl::GLImage* image, |
1478 GLStreamTextureImage* stream_texture_image, | 1499 GLStreamTextureImage* stream_texture_image, |
1479 ImageState state) { | 1500 ImageState state) { |
| 1501 DCHECK(!stream_texture_image || stream_texture_image == image); |
1480 DCHECK_GE(level, 0); | 1502 DCHECK_GE(level, 0); |
1481 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1503 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1482 DCHECK_LT(static_cast<size_t>(face_index), | 1504 DCHECK_LT(static_cast<size_t>(face_index), |
1483 face_infos_.size()); | 1505 face_infos_.size()); |
1484 DCHECK_LT(static_cast<size_t>(level), | 1506 DCHECK_LT(static_cast<size_t>(level), |
1485 face_infos_[face_index].level_infos.size()); | 1507 face_infos_[face_index].level_infos.size()); |
1486 Texture::LevelInfo& info = | 1508 Texture::LevelInfo& info = |
1487 face_infos_[face_index].level_infos[level]; | 1509 face_infos_[face_index].level_infos[level]; |
1488 DCHECK_EQ(info.target, target); | 1510 DCHECK_EQ(info.target, target); |
1489 DCHECK_EQ(info.level, level); | 1511 DCHECK_EQ(info.level, level); |
1490 info.image = image; | 1512 |
1491 info.stream_texture_image = stream_texture_image; | 1513 if (info.image != image) { |
| 1514 info.image = image; |
| 1515 info.stream_texture_image = stream_texture_image; |
| 1516 // If |stream_texture_image| is changing we have to reset the stream texture |
| 1517 // service id if one was set. This is important because if the outgoing |
| 1518 // image owns the stream texture service id, then |service_id_| may no |
| 1519 // longer be valid after the previous image is destructed. |
| 1520 SetStreamTextureServiceId(0); |
| 1521 } |
1492 info.image_state = state; | 1522 info.image_state = state; |
1493 | 1523 |
1494 UpdateCanRenderCondition(); | 1524 UpdateCanRenderCondition(); |
1495 UpdateHasImages(); | 1525 UpdateHasImages(); |
1496 UpdateEmulatingRGB(); | 1526 UpdateEmulatingRGB(); |
1497 } | 1527 } |
1498 | 1528 |
1499 void Texture::SetLevelImage(GLenum target, | 1529 void Texture::SetLevelImage(GLenum target, |
1500 GLint level, | 1530 GLint level, |
1501 gl::GLImage* image, | 1531 gl::GLImage* image, |
1502 ImageState state) { | 1532 ImageState state) { |
1503 SetLevelImageInternal(target, level, image, nullptr, state); | 1533 SetLevelImageInternal(target, level, image, nullptr, state); |
1504 } | 1534 } |
1505 | 1535 |
1506 void Texture::SetLevelStreamTextureImage(GLenum target, | 1536 void Texture::SetLevelStreamTextureImage(GLenum target, |
1507 GLint level, | 1537 GLint level, |
1508 GLStreamTextureImage* image, | 1538 GLStreamTextureImage* image, |
1509 ImageState state) { | 1539 ImageState state, |
| 1540 GLuint service_id) { |
1510 SetLevelImageInternal(target, level, image, image, state); | 1541 SetLevelImageInternal(target, level, image, image, state); |
| 1542 SetStreamTextureServiceId(service_id); |
1511 } | 1543 } |
1512 | 1544 |
1513 const Texture::LevelInfo* Texture::GetLevelInfo(GLint target, | 1545 const Texture::LevelInfo* Texture::GetLevelInfo(GLint target, |
1514 GLint level) const { | 1546 GLint level) const { |
1515 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1547 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
1516 target != GL_TEXTURE_RECTANGLE_ARB) { | 1548 target != GL_TEXTURE_RECTANGLE_ARB) { |
1517 return NULL; | 1549 return NULL; |
1518 } | 1550 } |
1519 | 1551 |
1520 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1552 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 feature_info->validators()-> | 1644 feature_info->validators()-> |
1613 texture_sized_color_renderable_internal_format.IsValid( | 1645 texture_sized_color_renderable_internal_format.IsValid( |
1614 internal_format)); | 1646 internal_format)); |
1615 bool depth_renderable = feature_info->validators()-> | 1647 bool depth_renderable = feature_info->validators()-> |
1616 texture_depth_renderable_internal_format.IsValid(internal_format); | 1648 texture_depth_renderable_internal_format.IsValid(internal_format); |
1617 bool stencil_renderable = feature_info->validators()-> | 1649 bool stencil_renderable = feature_info->validators()-> |
1618 texture_stencil_renderable_internal_format.IsValid(internal_format); | 1650 texture_stencil_renderable_internal_format.IsValid(internal_format); |
1619 return (color_renderable || depth_renderable || stencil_renderable); | 1651 return (color_renderable || depth_renderable || stencil_renderable); |
1620 } | 1652 } |
1621 | 1653 |
1622 void Texture::SetUnownedServiceId(GLuint service_id) { | |
1623 GLuint new_service_id = service_id; | |
1624 | |
1625 // Take no action if this isn't an OES_EXTERNAL texture. | |
1626 if (target_ && target_ != GL_TEXTURE_EXTERNAL_OES) | |
1627 return; | |
1628 | |
1629 if (!service_id) | |
1630 new_service_id = owned_service_id_; | |
1631 | |
1632 if (service_id_ != new_service_id) { | |
1633 service_id_ = new_service_id; | |
1634 IncrementManagerServiceIdGeneration(); | |
1635 if (gl::GLContext* context = gl::GLContext::GetCurrent()) { | |
1636 // It would be preferable to pass in the decoder, and ask it to do this | |
1637 // instead. However, there are several cases, such as TextureDefinition, | |
1638 // that show up without a clear context owner. So, instead, we use the | |
1639 // current state's state restorer. | |
1640 if (gl::GLStateRestorer* restorer = context->GetGLStateRestorer()) | |
1641 restorer->RestoreAllExternalTextureBindingsIfNeeded(); | |
1642 } | |
1643 } | |
1644 } | |
1645 | |
1646 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { | 1654 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { |
1647 return GetSwizzleForChannel(channel, compatibility_swizzle_); | 1655 return GetSwizzleForChannel(channel, compatibility_swizzle_); |
1648 } | 1656 } |
1649 | 1657 |
1650 void Texture::SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle) { | 1658 void Texture::SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle) { |
1651 if (compatibility_swizzle_ == swizzle) | 1659 if (compatibility_swizzle_ == swizzle) |
1652 return; | 1660 return; |
1653 | 1661 |
1654 compatibility_swizzle_ = swizzle; | 1662 compatibility_swizzle_ = swizzle; |
1655 glTexParameteri(target_, GL_TEXTURE_SWIZZLE_R, | 1663 glTexParameteri(target_, GL_TEXTURE_SWIZZLE_R, |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 gl::GLImage* image, | 2101 gl::GLImage* image, |
2094 Texture::ImageState state) { | 2102 Texture::ImageState state) { |
2095 DCHECK(ref); | 2103 DCHECK(ref); |
2096 ref->texture()->SetLevelImage(target, level, image, state); | 2104 ref->texture()->SetLevelImage(target, level, image, state); |
2097 } | 2105 } |
2098 | 2106 |
2099 void TextureManager::SetLevelStreamTextureImage(TextureRef* ref, | 2107 void TextureManager::SetLevelStreamTextureImage(TextureRef* ref, |
2100 GLenum target, | 2108 GLenum target, |
2101 GLint level, | 2109 GLint level, |
2102 GLStreamTextureImage* image, | 2110 GLStreamTextureImage* image, |
2103 Texture::ImageState state) { | 2111 Texture::ImageState state, |
| 2112 GLuint service_id) { |
2104 DCHECK(ref); | 2113 DCHECK(ref); |
2105 ref->texture()->SetLevelStreamTextureImage(target, level, image, state); | 2114 ref->texture()->SetLevelStreamTextureImage(target, level, image, state, |
| 2115 service_id); |
2106 } | 2116 } |
2107 | 2117 |
2108 size_t TextureManager::GetSignatureSize() const { | 2118 size_t TextureManager::GetSignatureSize() const { |
2109 return sizeof(TextureTag) + sizeof(TextureSignature); | 2119 return sizeof(TextureTag) + sizeof(TextureSignature); |
2110 } | 2120 } |
2111 | 2121 |
2112 void TextureManager::AddToSignature( | 2122 void TextureManager::AddToSignature( |
2113 TextureRef* ref, | 2123 TextureRef* ref, |
2114 GLenum target, | 2124 GLenum target, |
2115 GLint level, | 2125 GLint level, |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3309 uint32_t TextureManager::GetServiceIdGeneration() const { | 3319 uint32_t TextureManager::GetServiceIdGeneration() const { |
3310 return current_service_id_generation_; | 3320 return current_service_id_generation_; |
3311 } | 3321 } |
3312 | 3322 |
3313 void TextureManager::IncrementServiceIdGeneration() { | 3323 void TextureManager::IncrementServiceIdGeneration() { |
3314 current_service_id_generation_++; | 3324 current_service_id_generation_++; |
3315 } | 3325 } |
3316 | 3326 |
3317 } // namespace gles2 | 3327 } // namespace gles2 |
3318 } // namespace gpu | 3328 } // namespace gpu |
OLD | NEW |