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 "cc/nine_patch_layer.h" | 5 #include "cc/nine_patch_layer.h" |
6 | 6 |
7 #include "cc/layer_tree_host.h" | 7 #include "cc/layer_tree_host.h" |
8 #include "cc/nine_patch_layer_impl.h" | 8 #include "cc/nine_patch_layer_impl.h" |
9 #include "cc/resource_update.h" | 9 #include "cc/resource_update.h" |
10 #include "cc/resource_update_queue.h" | 10 #include "cc/resource_update_queue.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 { | 25 { |
26 } | 26 } |
27 | 27 |
28 scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl() | 28 scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl() |
29 { | 29 { |
30 return NinePatchLayerImpl::create(id()).PassAs<LayerImpl>(); | 30 return NinePatchLayerImpl::create(id()).PassAs<LayerImpl>(); |
31 } | 31 } |
32 | 32 |
33 void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc
) | 33 void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc
) |
34 { | 34 { |
35 if (m_needsDisplay && m_bitmapDirty && drawsContent()) { | 35 if (m_resource && !m_resource->texture()->resourceManager()) { |
36 DCHECK(!m_bitmap.isNull()); | 36 // Release the resource here, as it is no longer tied to a resource mana
ger. |
37 createUpdaterIfNeeded(); | 37 m_resource.reset(); |
38 m_updater->setBitmap(m_bitmap); | 38 if (!m_bitmap.isNull()) |
39 m_needsDisplay = false; | 39 createResource(); |
40 | 40 } else if (m_needsDisplay && m_bitmapDirty && drawsContent()) { |
41 if (!m_resource) | 41 createResource(); |
42 m_resource = m_updater->createResource(layerTreeHost()->contentsText
ureManager()); | |
43 } | 42 } |
44 | 43 |
45 if (m_resource) { | 44 if (m_resource) { |
46 m_resource->texture()->setRequestPriority(PriorityCalculator::uiPriority
(true)); | 45 m_resource->texture()->setRequestPriority(PriorityCalculator::uiPriority
(true)); |
47 // FIXME: Need to support swizzle in the shader for !PlatformColor::same
ComponentOrder(textureFormat) | 46 // FIXME: Need to support swizzle in the shader for !PlatformColor::same
ComponentOrder(textureFormat) |
48 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextu
reFormat; | 47 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextu
reFormat; |
49 m_resource->texture()->setDimensions(gfx::Size(m_bitmap.width(), m_bitma
p.height()), textureFormat); | 48 m_resource->texture()->setDimensions(gfx::Size(m_bitmap.width(), m_bitma
p.height()), textureFormat); |
50 } | 49 } |
51 } | 50 } |
52 | 51 |
(...skipping 17 matching lines...) Expand all Loading... |
70 } | 69 } |
71 | 70 |
72 void NinePatchLayer::createUpdaterIfNeeded() | 71 void NinePatchLayer::createUpdaterIfNeeded() |
73 { | 72 { |
74 if (m_updater) | 73 if (m_updater) |
75 return; | 74 return; |
76 | 75 |
77 m_updater = ImageLayerUpdater::create(); | 76 m_updater = ImageLayerUpdater::create(); |
78 } | 77 } |
79 | 78 |
| 79 void NinePatchLayer::createResource() |
| 80 { |
| 81 DCHECK(!m_bitmap.isNull()); |
| 82 createUpdaterIfNeeded(); |
| 83 m_updater->setBitmap(m_bitmap); |
| 84 m_needsDisplay = false; |
| 85 |
| 86 if (!m_resource) |
| 87 m_resource = m_updater->createResource(layerTreeHost()->contentsTextureM
anager()); |
| 88 } |
| 89 |
80 bool NinePatchLayer::drawsContent() const | 90 bool NinePatchLayer::drawsContent() const |
81 { | 91 { |
82 bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width()
&& m_bitmap.height(); | 92 bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width()
&& m_bitmap.height(); |
83 return draws; | 93 return draws; |
84 } | 94 } |
85 | 95 |
86 void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) | 96 void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) |
87 { | 97 { |
88 Layer::pushPropertiesTo(layer); | 98 Layer::pushPropertiesTo(layer); |
89 NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer); | 99 NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer); |
90 | 100 |
91 if (m_resource) { | 101 if (m_resource) { |
92 DCHECK(!m_bitmap.isNull()); | 102 DCHECK(!m_bitmap.isNull()); |
93 layerImpl->setResourceId(m_resource->texture()->resourceId()); | 103 layerImpl->setResourceId(m_resource->texture()->resourceId()); |
94 layerImpl->setLayout(gfx::Size(m_bitmap.width(), m_bitmap.height()), m_i
mageAperture); | 104 layerImpl->setLayout(gfx::Size(m_bitmap.width(), m_bitmap.height()), m_i
mageAperture); |
95 } | 105 } |
96 } | 106 } |
97 | 107 |
98 } | 108 } |
OLD | NEW |