| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "cc/prioritized_texture.h" | 7 #include "cc/prioritized_texture.h" |
| 8 | 8 |
| 9 #include "cc/platform_color.h" | 9 #include "cc/platform_color.h" |
| 10 #include "cc/prioritized_texture_manager.h" | 10 #include "cc/prioritized_texture_manager.h" |
| 11 #include "cc/priority_calculator.h" | 11 #include "cc/priority_calculator.h" |
| 12 #include "cc/proxy.h" | 12 #include "cc/proxy.h" |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 | 14 |
| 15 using namespace std; | 15 using namespace std; |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 PrioritizedTexture::PrioritizedTexture(PrioritizedTextureManager* manager, IntSi
ze size, GLenum format) | 19 PrioritizedTexture::PrioritizedTexture(PrioritizedTextureManager* manager, gfx::
Size size, GLenum format) |
| 20 : m_size(size) | 20 : m_size(size) |
| 21 , m_format(format) | 21 , m_format(format) |
| 22 , m_bytes(0) | 22 , m_bytes(0) |
| 23 , m_contentsSwizzled(false) | 23 , m_contentsSwizzled(false) |
| 24 , m_priority(PriorityCalculator::lowestPriority()) | 24 , m_priority(PriorityCalculator::lowestPriority()) |
| 25 , m_isAbovePriorityCutoff(false) | 25 , m_isAbovePriorityCutoff(false) |
| 26 , m_isSelfManaged(false) | 26 , m_isSelfManaged(false) |
| 27 , m_backing(0) | 27 , m_backing(0) |
| 28 , m_manager(0) | 28 , m_manager(0) |
| 29 { | 29 { |
| 30 // m_manager is set in registerTexture() so validity can be checked. | 30 // m_manager is set in registerTexture() so validity can be checked. |
| 31 DCHECK(format || size.isEmpty()); | 31 DCHECK(format || size.IsEmpty()); |
| 32 if (format) | 32 if (format) |
| 33 m_bytes = Texture::memorySizeBytes(size, format); | 33 m_bytes = Texture::memorySizeBytes(size, format); |
| 34 if (manager) | 34 if (manager) |
| 35 manager->registerTexture(this); | 35 manager->registerTexture(this); |
| 36 } | 36 } |
| 37 | 37 |
| 38 PrioritizedTexture::~PrioritizedTexture() | 38 PrioritizedTexture::~PrioritizedTexture() |
| 39 { | 39 { |
| 40 if (m_manager) | 40 if (m_manager) |
| 41 m_manager->unregisterTexture(this); | 41 m_manager->unregisterTexture(this); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void PrioritizedTexture::setTextureManager(PrioritizedTextureManager* manager) | 44 void PrioritizedTexture::setTextureManager(PrioritizedTextureManager* manager) |
| 45 { | 45 { |
| 46 if (m_manager == manager) | 46 if (m_manager == manager) |
| 47 return; | 47 return; |
| 48 if (m_manager) | 48 if (m_manager) |
| 49 m_manager->unregisterTexture(this); | 49 m_manager->unregisterTexture(this); |
| 50 if (manager) | 50 if (manager) |
| 51 manager->registerTexture(this); | 51 manager->registerTexture(this); |
| 52 } | 52 } |
| 53 | 53 |
| 54 void PrioritizedTexture::setDimensions(IntSize size, GLenum format) | 54 void PrioritizedTexture::setDimensions(gfx::Size size, GLenum format) |
| 55 { | 55 { |
| 56 if (m_format != format || m_size != size) { | 56 if (m_format != format || m_size != size) { |
| 57 m_isAbovePriorityCutoff = false; | 57 m_isAbovePriorityCutoff = false; |
| 58 m_format = format; | 58 m_format = format; |
| 59 m_size = size; | 59 m_size = size; |
| 60 m_bytes = Texture::memorySizeBytes(size, format); | 60 m_bytes = Texture::memorySizeBytes(size, format); |
| 61 DCHECK(m_manager || !m_backing); | 61 DCHECK(m_manager || !m_backing); |
| 62 if (m_manager) | 62 if (m_manager) |
| 63 m_manager->returnBackingTexture(this); | 63 m_manager->returnBackingTexture(this); |
| 64 } | 64 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 84 } | 84 } |
| 85 | 85 |
| 86 ResourceProvider::ResourceId PrioritizedTexture::resourceId() const | 86 ResourceProvider::ResourceId PrioritizedTexture::resourceId() const |
| 87 { | 87 { |
| 88 if (m_backing) | 88 if (m_backing) |
| 89 return m_backing->id(); | 89 return m_backing->id(); |
| 90 return 0; | 90 return 0; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PrioritizedTexture::upload(ResourceProvider* resourceProvider, | 93 void PrioritizedTexture::upload(ResourceProvider* resourceProvider, |
| 94 const uint8_t* image, const IntRect& imageRect
, | 94 const uint8_t* image, const gfx::Rect& imageRect
, |
| 95 const IntRect& sourceRect, const IntSize& dest
Offset) | 95 const gfx::Rect& sourceRect, const gfx::Vector2d
& destOffset) |
| 96 { | 96 { |
| 97 DCHECK(m_isAbovePriorityCutoff); | 97 DCHECK(m_isAbovePriorityCutoff); |
| 98 if (m_isAbovePriorityCutoff) | 98 if (m_isAbovePriorityCutoff) |
| 99 acquireBackingTexture(resourceProvider); | 99 acquireBackingTexture(resourceProvider); |
| 100 DCHECK(m_backing); | 100 DCHECK(m_backing); |
| 101 resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOff
set); | 101 resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOff
set); |
| 102 | 102 |
| 103 // The component order may be bgra if we uploaded bgra pixels to rgba | 103 // The component order may be bgra if we uploaded bgra pixels to rgba |
| 104 // texture. Mark contents as swizzled if image component order is | 104 // texture. Mark contents as swizzled if image component order is |
| 105 // different than texture format. | 105 // different than texture format. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 120 { | 120 { |
| 121 DCHECK(m_backing); | 121 DCHECK(m_backing); |
| 122 DCHECK(m_backing->m_owner == this); | 122 DCHECK(m_backing->m_owner == this); |
| 123 | 123 |
| 124 m_backing->m_owner = 0; | 124 m_backing->m_owner = 0; |
| 125 m_backing = 0; | 125 m_backing = 0; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void PrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) | 128 void PrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) |
| 129 { | 129 { |
| 130 setDimensions(IntSize(), GL_RGBA); | 130 setDimensions(gfx::Size(), GL_RGBA); |
| 131 setIsSelfManaged(true); | 131 setIsSelfManaged(true); |
| 132 m_bytes = bytes; | 132 m_bytes = bytes; |
| 133 } | 133 } |
| 134 | 134 |
| 135 PrioritizedTexture::Backing::Backing(unsigned id, ResourceProvider* resourceProv
ider, IntSize size, GLenum format) | 135 PrioritizedTexture::Backing::Backing(unsigned id, ResourceProvider* resourceProv
ider, gfx::Size size, GLenum format) |
| 136 : Texture(id, size, format) | 136 : Texture(id, size, format) |
| 137 , m_owner(0) | 137 , m_owner(0) |
| 138 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority()) | 138 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority()) |
| 139 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) | 139 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) |
| 140 , m_inDrawingImplTree(false) | 140 , m_inDrawingImplTree(false) |
| 141 , m_resourceHasBeenDeleted(false) | 141 , m_resourceHasBeenDeleted(false) |
| 142 #ifndef NDEBUG | 142 #ifndef NDEBUG |
| 143 , m_resourceProvider(resourceProvider) | 143 , m_resourceProvider(resourceProvider) |
| 144 #endif | 144 #endif |
| 145 { | 145 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 197 } |
| 198 | 198 |
| 199 void PrioritizedTexture::returnBackingTexture() | 199 void PrioritizedTexture::returnBackingTexture() |
| 200 { | 200 { |
| 201 DCHECK(m_manager || !m_backing); | 201 DCHECK(m_manager || !m_backing); |
| 202 if (m_manager) | 202 if (m_manager) |
| 203 m_manager->returnBackingTexture(this); | 203 m_manager->returnBackingTexture(this); |
| 204 } | 204 } |
| 205 | 205 |
| 206 } // namespace cc | 206 } // namespace cc |
| OLD | NEW |