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

Unified Diff: cc/DecorationLayerChromium.cpp

Issue 10963056: [cc] Add window decoration layers (NinePatch) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: hacky rebase for Jerome to use Created 8 years, 2 months 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
« no previous file with comments | « cc/DecorationLayerChromium.h ('k') | cc/DecorationLayerChromiumTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/DecorationLayerChromium.cpp
diff --git a/cc/DecorationLayerChromium.cpp b/cc/DecorationLayerChromium.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..6f9d48744da26486b5b609c6a23f4a3bb50a6697
--- /dev/null
+++ b/cc/DecorationLayerChromium.cpp
@@ -0,0 +1,158 @@
+// 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 "DecorationLayerChromium.h"
+
+#include "CCLayerTreeHost.h"
+#include "CCDecorationLayerImpl.h"
+#include "CCTextureUpdateQueue.h"
+#include "LayerTextureUpdater.h"
+#include "PlatformColor.h"
+#include "TextureUploader.h"
+
+namespace cc {
+
+class DecorationLayerTextureUpdater : public LayerTextureUpdater {
+public:
+ class Texture : public LayerTextureUpdater::Texture {
+ public:
+ Texture(DecorationLayerTextureUpdater* textureUpdater, scoped_ptr<CCPrioritizedTexture> texture)
+ : LayerTextureUpdater::Texture(texture.Pass())
+ , m_textureUpdater(textureUpdater)
+ {
+ }
+
+ virtual void update(CCTextureUpdateQueue& queue, const IntRect& sourceRect, const IntSize& destOffset, bool partialUpdate, CCRenderingStats&) OVERRIDE
+ {
+ }
+
+ private:
+ DecorationLayerTextureUpdater* textureUpdater() { return m_textureUpdater; }
+
+ DecorationLayerTextureUpdater* m_textureUpdater;
+ };
+
+ static PassRefPtr<DecorationLayerTextureUpdater> create()
+ {
+ return adoptRef(new DecorationLayerTextureUpdater());
+ }
+
+ virtual ~DecorationLayerTextureUpdater() { }
+
+ virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(CCPrioritizedTextureManager* manager)
+ {
+ ASSERT(!m_bitmap.isNull());
+
+ scoped_ptr<CCPrioritizedTexture> texture = CCPrioritizedTexture::create(manager);
+ return adoptPtr(new Texture(this, texture.Pass()));
+ }
+
+ virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRIDE
+ {
+ return PlatformColor::sameComponentOrder(textureFormat) ?
+ LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
+ }
+
+ void setBitmap(const SkBitmap& bitmap)
+ {
+ m_bitmap = bitmap;
+ }
+
+private:
+ DecorationLayerTextureUpdater() { }
+ SkBitmap m_bitmap;
+};
+
+scoped_refptr<DecorationLayerChromium> DecorationLayerChromium::create()
+{
+ return make_scoped_refptr(new DecorationLayerChromium());
+}
+
+DecorationLayerChromium::DecorationLayerChromium()
+ : LayerChromium()
+ , m_bitmapDirty(false)
+{
+}
+
+DecorationLayerChromium::~DecorationLayerChromium()
+{
+}
+
+scoped_ptr<CCLayerImpl> DecorationLayerChromium::createCCLayerImpl()
+{
+ return CCDecorationLayerImpl::create(id()).PassAs<CCLayerImpl>();
+}
+
+void DecorationLayerChromium::setTexturePriorities(const CCPriorityCalculator& priorityCalc)
+{
+ if (m_needsDisplay && m_bitmapDirty && drawsContent()) {
+ ASSERT(!m_bitmap.isNull());
+ createTextureUpdaterIfNeeded();
+ m_textureUpdater->setBitmap(m_bitmap);
+ m_needsDisplay = false;
+
+ if (!m_texture.get())
+ m_texture = m_textureUpdater->createTexture(layerTreeHost()->contentsTextureManager());
+ }
+
+ if (m_texture.get()) {
+ m_texture->texture()->setRequestPriority(CCPriorityCalculator::uiPriority(true));
+ // FIXME: Need to support swizzle in the shader for !PlatformColor::sameComponentOrder(textureFormat)
+ GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTextureFormat;
+ m_texture->texture()->setDimensions(IntSize(m_bitmap.width(), m_bitmap.height()), textureFormat);
+ }
+}
+
+void DecorationLayerChromium::setBitmap(const SkBitmap& bitmap, const IntRect& aperture) {
+ m_bitmap = bitmap;
+ m_imageAperture = aperture;
+ m_bitmapDirty = true;
+ setNeedsDisplay();
+}
+
+void DecorationLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker* occlusion, CCRenderingStats& stats)
+{
+ createTextureUpdaterIfNeeded();
+
+ // FIXME: Or should this query backingResourceWasEvicted()?
+ if (m_texture.get() && (m_bitmapDirty || !m_texture->texture()->haveBackingTexture())) {
+ IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bitmap.height()));
+ TextureUploader::Parameters upload = { m_texture->texture(), &m_bitmap, NULL, { contentRect, contentRect, IntSize() } };
+ queue.appendFullUpload(upload);
+ m_bitmapDirty = false;
+ }
+}
+
+void DecorationLayerChromium::createTextureUpdaterIfNeeded()
+{
+ if (m_textureUpdater)
+ return;
+
+ m_textureUpdater = DecorationLayerTextureUpdater::create();
+}
+
+bool DecorationLayerChromium::drawsContent() const
+{
+ bool draws = !m_bitmap.isNull() && LayerChromium::drawsContent() && m_bitmap.width() && m_bitmap.height();
+ return draws;
+}
+
+bool DecorationLayerChromium::needsContentsScale() const
+{
+ return false;
+}
+
+void DecorationLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
+{
+ LayerChromium::pushPropertiesTo(layer);
+ CCDecorationLayerImpl* layerImpl = static_cast<CCDecorationLayerImpl*>(layer);
+
+ if (m_texture.get())
+ layerImpl->setResourceId(m_texture->texture()->resourceId());
+ layerImpl->setDecorationLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
+}
+
+}
« no previous file with comments | « cc/DecorationLayerChromium.h ('k') | cc/DecorationLayerChromiumTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698