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), face_infos_.size()); |
1483 face_infos_.size()); | |
1484 DCHECK_LT(static_cast<size_t>(level), | 1505 DCHECK_LT(static_cast<size_t>(level), |
1485 face_infos_[face_index].level_infos.size()); | 1506 face_infos_[face_index].level_infos.size()); |
1486 Texture::LevelInfo& info = | 1507 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
1487 face_infos_[face_index].level_infos[level]; | |
1488 DCHECK_EQ(info.target, target); | 1508 DCHECK_EQ(info.target, target); |
1489 DCHECK_EQ(info.level, level); | 1509 DCHECK_EQ(info.level, level); |
1490 info.image = image; | 1510 info.image = image; |
1491 info.stream_texture_image = stream_texture_image; | 1511 info.stream_texture_image = stream_texture_image; |
1492 info.image_state = state; | 1512 info.image_state = state; |
1493 | 1513 |
1494 UpdateCanRenderCondition(); | 1514 UpdateCanRenderCondition(); |
1495 UpdateHasImages(); | 1515 UpdateHasImages(); |
1496 UpdateEmulatingRGB(); | 1516 UpdateEmulatingRGB(); |
1497 } | 1517 } |
1498 | 1518 |
1499 void Texture::SetLevelImage(GLenum target, | 1519 void Texture::SetLevelImage(GLenum target, |
1500 GLint level, | 1520 GLint level, |
1501 gl::GLImage* image, | 1521 gl::GLImage* image, |
1502 ImageState state) { | 1522 ImageState state) { |
| 1523 SetStreamTextureServiceId(0); |
1503 SetLevelImageInternal(target, level, image, nullptr, state); | 1524 SetLevelImageInternal(target, level, image, nullptr, state); |
1504 } | 1525 } |
1505 | 1526 |
1506 void Texture::SetLevelStreamTextureImage(GLenum target, | 1527 void Texture::SetLevelStreamTextureImage(GLenum target, |
1507 GLint level, | 1528 GLint level, |
1508 GLStreamTextureImage* image, | 1529 GLStreamTextureImage* image, |
1509 ImageState state) { | 1530 ImageState state, |
| 1531 GLuint service_id) { |
| 1532 SetStreamTextureServiceId(service_id); |
1510 SetLevelImageInternal(target, level, image, image, state); | 1533 SetLevelImageInternal(target, level, image, image, state); |
1511 } | 1534 } |
1512 | 1535 |
| 1536 void Texture::SetLevelImageState(GLenum target, GLint level, ImageState state) { |
| 1537 DCHECK_GE(level, 0); |
| 1538 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
| 1539 DCHECK_LT(static_cast<size_t>(face_index), face_infos_.size()); |
| 1540 DCHECK_LT(static_cast<size_t>(level), |
| 1541 face_infos_[face_index].level_infos.size()); |
| 1542 Texture::LevelInfo& info = face_infos_[face_index].level_infos[level]; |
| 1543 DCHECK_EQ(info.target, target); |
| 1544 DCHECK_EQ(info.level, level); |
| 1545 info.image_state = state; |
| 1546 } |
| 1547 |
1513 const Texture::LevelInfo* Texture::GetLevelInfo(GLint target, | 1548 const Texture::LevelInfo* Texture::GetLevelInfo(GLint target, |
1514 GLint level) const { | 1549 GLint level) const { |
1515 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && | 1550 if (target != GL_TEXTURE_2D && target != GL_TEXTURE_EXTERNAL_OES && |
1516 target != GL_TEXTURE_RECTANGLE_ARB) { | 1551 target != GL_TEXTURE_RECTANGLE_ARB) { |
1517 return NULL; | 1552 return NULL; |
1518 } | 1553 } |
1519 | 1554 |
1520 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); | 1555 size_t face_index = GLES2Util::GLTargetToFaceIndex(target); |
1521 if (level >= 0 && face_index < face_infos_.size() && | 1556 if (level >= 0 && face_index < face_infos_.size() && |
1522 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { | 1557 static_cast<size_t>(level) < face_infos_[face_index].level_infos.size()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1612 feature_info->validators()-> | 1647 feature_info->validators()-> |
1613 texture_sized_color_renderable_internal_format.IsValid( | 1648 texture_sized_color_renderable_internal_format.IsValid( |
1614 internal_format)); | 1649 internal_format)); |
1615 bool depth_renderable = feature_info->validators()-> | 1650 bool depth_renderable = feature_info->validators()-> |
1616 texture_depth_renderable_internal_format.IsValid(internal_format); | 1651 texture_depth_renderable_internal_format.IsValid(internal_format); |
1617 bool stencil_renderable = feature_info->validators()-> | 1652 bool stencil_renderable = feature_info->validators()-> |
1618 texture_stencil_renderable_internal_format.IsValid(internal_format); | 1653 texture_stencil_renderable_internal_format.IsValid(internal_format); |
1619 return (color_renderable || depth_renderable || stencil_renderable); | 1654 return (color_renderable || depth_renderable || stencil_renderable); |
1620 } | 1655 } |
1621 | 1656 |
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) { | 1657 GLenum Texture::GetCompatibilitySwizzleForChannel(GLenum channel) { |
1647 return GetSwizzleForChannel(channel, compatibility_swizzle_); | 1658 return GetSwizzleForChannel(channel, compatibility_swizzle_); |
1648 } | 1659 } |
1649 | 1660 |
1650 void Texture::SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle) { | 1661 void Texture::SetCompatibilitySwizzle(const CompatibilitySwizzle* swizzle) { |
1651 if (compatibility_swizzle_ == swizzle) | 1662 if (compatibility_swizzle_ == swizzle) |
1652 return; | 1663 return; |
1653 | 1664 |
1654 compatibility_swizzle_ = swizzle; | 1665 compatibility_swizzle_ = swizzle; |
1655 glTexParameteri(target_, GL_TEXTURE_SWIZZLE_R, | 1666 glTexParameteri(target_, GL_TEXTURE_SWIZZLE_R, |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2093 gl::GLImage* image, | 2104 gl::GLImage* image, |
2094 Texture::ImageState state) { | 2105 Texture::ImageState state) { |
2095 DCHECK(ref); | 2106 DCHECK(ref); |
2096 ref->texture()->SetLevelImage(target, level, image, state); | 2107 ref->texture()->SetLevelImage(target, level, image, state); |
2097 } | 2108 } |
2098 | 2109 |
2099 void TextureManager::SetLevelStreamTextureImage(TextureRef* ref, | 2110 void TextureManager::SetLevelStreamTextureImage(TextureRef* ref, |
2100 GLenum target, | 2111 GLenum target, |
2101 GLint level, | 2112 GLint level, |
2102 GLStreamTextureImage* image, | 2113 GLStreamTextureImage* image, |
2103 Texture::ImageState state) { | 2114 Texture::ImageState state, |
| 2115 GLuint service_id) { |
2104 DCHECK(ref); | 2116 DCHECK(ref); |
2105 ref->texture()->SetLevelStreamTextureImage(target, level, image, state); | 2117 ref->texture()->SetLevelStreamTextureImage(target, level, image, state, |
| 2118 service_id); |
| 2119 } |
| 2120 |
| 2121 void TextureManager::SetLevelImageState(TextureRef* ref, |
| 2122 GLenum target, |
| 2123 GLint level, |
| 2124 Texture::ImageState state) { |
| 2125 DCHECK(ref); |
| 2126 ref->texture()->SetLevelImageState(target, level, state); |
2106 } | 2127 } |
2107 | 2128 |
2108 size_t TextureManager::GetSignatureSize() const { | 2129 size_t TextureManager::GetSignatureSize() const { |
2109 return sizeof(TextureTag) + sizeof(TextureSignature); | 2130 return sizeof(TextureTag) + sizeof(TextureSignature); |
2110 } | 2131 } |
2111 | 2132 |
2112 void TextureManager::AddToSignature( | 2133 void TextureManager::AddToSignature( |
2113 TextureRef* ref, | 2134 TextureRef* ref, |
2114 GLenum target, | 2135 GLenum target, |
2115 GLint level, | 2136 GLint level, |
(...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3309 uint32_t TextureManager::GetServiceIdGeneration() const { | 3330 uint32_t TextureManager::GetServiceIdGeneration() const { |
3310 return current_service_id_generation_; | 3331 return current_service_id_generation_; |
3311 } | 3332 } |
3312 | 3333 |
3313 void TextureManager::IncrementServiceIdGeneration() { | 3334 void TextureManager::IncrementServiceIdGeneration() { |
3314 current_service_id_generation_++; | 3335 current_service_id_generation_++; |
3315 } | 3336 } |
3316 | 3337 |
3317 } // namespace gles2 | 3338 } // namespace gles2 |
3318 } // namespace gpu | 3339 } // namespace gpu |
OLD | NEW |