OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include "cc/nine_patch_layer.h" | |
8 | |
9 #include "cc/layer_tree_host.h" | |
10 #include "cc/nine_patch_layer_impl.h" | |
11 #include "cc/resource_update.h" | |
12 #include "cc/resource_update_queue.h" | |
13 | |
14 namespace cc { | |
15 | |
16 scoped_refptr<NinePatchLayer> NinePatchLayer::create() | |
17 { | |
18 return make_scoped_refptr(new NinePatchLayer()); | |
19 } | |
20 | |
21 NinePatchLayer::NinePatchLayer() | |
22 : m_bitmapDirty(false) | |
23 { | |
24 } | |
25 | |
26 NinePatchLayer::~NinePatchLayer() | |
27 { | |
28 } | |
29 | |
30 scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl() | |
31 { | |
32 return NinePatchLayerImpl::create(id()).PassAs<LayerImpl>(); | |
33 } | |
34 | |
35 void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc ) | |
36 { | |
37 if (m_needsDisplay && m_bitmapDirty && drawsContent()) { | |
38 DCHECK(!m_bitmap.isNull()); | |
39 createUpdaterIfNeeded(); | |
40 m_updater->setBitmap(m_bitmap); | |
41 m_needsDisplay = false; | |
42 | |
43 if (!m_resource.get()) | |
jamesr
2012/11/01 19:55:43
fyi - you can null check scoped_ptr<>s by just say
| |
44 m_resource = m_updater->createResource(layerTreeHost()->contentsText ureManager()); | |
45 } | |
46 | |
47 if (m_resource.get()) { | |
48 m_resource->texture()->setRequestPriority(PriorityCalculator::uiPriority (true)); | |
49 // FIXME: Need to support swizzle in the shader for !PlatformColor::same ComponentOrder(textureFormat) | |
50 GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextu reFormat; | |
51 m_resource->texture()->setDimensions(IntSize(m_bitmap.width(), m_bitmap. height()), textureFormat); | |
52 } | |
53 } | |
54 | |
55 void NinePatchLayer::setBitmap(const SkBitmap& bitmap, const IntRect& aperture) { | |
56 m_bitmap = bitmap; | |
57 m_imageAperture = aperture; | |
58 m_bitmapDirty = true; | |
59 setNeedsDisplay(); | |
60 } | |
61 | |
62 void NinePatchLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats) | |
63 { | |
64 createUpdaterIfNeeded(); | |
65 | |
66 // FIXME: Or should this query backingResourceWasEvicted()? | |
67 if (m_resource.get() && (m_bitmapDirty || !m_resource->texture()->haveBackin gTexture())) { | |
68 IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bi tmap.height())); | |
69 ResourceUpdate upload = ResourceUpdate::Create(m_resource->texture(), &m _bitmap, contentRect, contentRect, gfx::Vector2d()); | |
70 queue.appendFullUpload(upload); | |
71 m_bitmapDirty = false; | |
72 } | |
73 } | |
74 | |
75 void NinePatchLayer::createUpdaterIfNeeded() | |
76 { | |
77 if (m_updater) | |
78 return; | |
79 | |
80 m_updater = ImageLayerUpdater::create(); | |
81 } | |
82 | |
83 bool NinePatchLayer::drawsContent() const | |
84 { | |
85 bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width() && m_bitmap.height(); | |
86 return draws; | |
87 } | |
88 | |
89 void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) | |
90 { | |
91 Layer::pushPropertiesTo(layer); | |
92 NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer); | |
93 | |
94 if (m_resource.get()) | |
jamesr
2012/11/01 19:55:43
does m_resource ever go null after creation? if it
aelias_OOO_until_Jul13
2012/11/02 07:38:16
No, it should never go null. This is just in case
danakj
2012/11/02 16:04:14
Should we just DCHECK in setTexturePriorities() or
aelias_OOO_until_Jul13
2012/11/06 01:15:00
Switched to DCHECKs.
| |
95 layerImpl->setResourceId(m_resource->texture()->resourceId()); | |
96 layerImpl->setNinePatchLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture); | |
97 } | |
98 | |
99 } | |
OLD | NEW |