Chromium Code Reviews| 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) | |
| 44 m_resource = m_updater->createResource(layerTreeHost()->contentsText ureManager()); | |
| 45 } | |
| 46 | |
| 47 if (m_resource) { | |
| 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 gfx::Rect& 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 if (m_resource.get() && (m_bitmapDirty || m_resource->texture()->backingReso urceWasEvicted())) { | |
|
jamesr
2012/11/05 23:10:53
just "if (m_resource && ...", no need for the .get
aelias_OOO_until_Jul13
2012/11/06 01:15:00
Changed to DCHECK anyway.
| |
| 67 gfx::Rect contentRect(gfx::Point(), gfx::Size(m_bitmap.width(), m_bitmap .height())); | |
| 68 ResourceUpdate upload = ResourceUpdate::Create(m_resource->texture(), &m _bitmap, contentRect, contentRect, gfx::Vector2d()); | |
| 69 queue.appendFullUpload(upload); | |
| 70 m_bitmapDirty = false; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void NinePatchLayer::createUpdaterIfNeeded() | |
| 75 { | |
| 76 if (m_updater) | |
| 77 return; | |
| 78 | |
| 79 m_updater = ImageLayerUpdater::create(); | |
| 80 } | |
| 81 | |
| 82 bool NinePatchLayer::drawsContent() const | |
| 83 { | |
| 84 bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width() && m_bitmap.height(); | |
| 85 return draws; | |
| 86 } | |
| 87 | |
| 88 void NinePatchLayer::pushPropertiesTo(LayerImpl* layer) | |
| 89 { | |
| 90 Layer::pushPropertiesTo(layer); | |
| 91 NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer); | |
| 92 | |
| 93 if (m_resource) | |
| 94 layerImpl->setResourceId(m_resource->texture()->resourceId()); | |
| 95 layerImpl->setLayout(gfx::Size(m_bitmap.width(), m_bitmap.height()), m_image Aperture); | |
| 96 } | |
| 97 | |
| 98 } | |
| OLD | NEW |