Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3639)

Unified Diff: cc/nine_patch_layer.cc

Issue 11304020: cc: Nine patch layer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed rebase to 165291 Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/nine_patch_layer.cc
diff --git a/cc/nine_patch_layer.cc b/cc/nine_patch_layer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..889efe589c3ba39504e11754b9f64dc1f6ebc49c
--- /dev/null
+++ b/cc/nine_patch_layer.cc
@@ -0,0 +1,99 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+
+#include "cc/nine_patch_layer.h"
+
+#include "cc/layer_tree_host.h"
+#include "cc/nine_patch_layer_impl.h"
+#include "cc/resource_update.h"
+#include "cc/resource_update_queue.h"
+
+namespace cc {
+
+scoped_refptr<NinePatchLayer> NinePatchLayer::create()
+{
+ return make_scoped_refptr(new NinePatchLayer());
+}
+
+NinePatchLayer::NinePatchLayer()
+ : m_bitmapDirty(false)
+{
+}
+
+NinePatchLayer::~NinePatchLayer()
+{
+}
+
+scoped_ptr<LayerImpl> NinePatchLayer::createLayerImpl()
+{
+ return NinePatchLayerImpl::create(id()).PassAs<LayerImpl>();
+}
+
+void NinePatchLayer::setTexturePriorities(const PriorityCalculator& priorityCalc)
+{
+ if (m_needsDisplay && m_bitmapDirty && drawsContent()) {
+ DCHECK(!m_bitmap.isNull());
+ createUpdaterIfNeeded();
+ m_updater->setBitmap(m_bitmap);
+ m_needsDisplay = false;
+
+ if (!m_resource.get())
jamesr 2012/11/01 19:55:43 fyi - you can null check scoped_ptr<>s by just say
+ m_resource = m_updater->createResource(layerTreeHost()->contentsTextureManager());
+ }
+
+ if (m_resource.get()) {
+ m_resource->texture()->setRequestPriority(PriorityCalculator::uiPriority(true));
+ // FIXME: Need to support swizzle in the shader for !PlatformColor::sameComponentOrder(textureFormat)
+ GLenum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
+ m_resource->texture()->setDimensions(IntSize(m_bitmap.width(), m_bitmap.height()), textureFormat);
+ }
+}
+
+void NinePatchLayer::setBitmap(const SkBitmap& bitmap, const IntRect& aperture) {
+ m_bitmap = bitmap;
+ m_imageAperture = aperture;
+ m_bitmapDirty = true;
+ setNeedsDisplay();
+}
+
+void NinePatchLayer::update(ResourceUpdateQueue& queue, const OcclusionTracker* occlusion, RenderingStats& stats)
+{
+ createUpdaterIfNeeded();
+
+ // FIXME: Or should this query backingResourceWasEvicted()?
+ if (m_resource.get() && (m_bitmapDirty || !m_resource->texture()->haveBackingTexture())) {
+ IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bitmap.height()));
+ ResourceUpdate upload = ResourceUpdate::Create(m_resource->texture(), &m_bitmap, contentRect, contentRect, gfx::Vector2d());
+ queue.appendFullUpload(upload);
+ m_bitmapDirty = false;
+ }
+}
+
+void NinePatchLayer::createUpdaterIfNeeded()
+{
+ if (m_updater)
+ return;
+
+ m_updater = ImageLayerUpdater::create();
+}
+
+bool NinePatchLayer::drawsContent() const
+{
+ bool draws = !m_bitmap.isNull() && Layer::drawsContent() && m_bitmap.width() && m_bitmap.height();
+ return draws;
+}
+
+void NinePatchLayer::pushPropertiesTo(LayerImpl* layer)
+{
+ Layer::pushPropertiesTo(layer);
+ NinePatchLayerImpl* layerImpl = static_cast<NinePatchLayerImpl*>(layer);
+
+ 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.
+ layerImpl->setResourceId(m_resource->texture()->resourceId());
+ layerImpl->setNinePatchLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698