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

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: Created 8 years, 3 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
Index: cc/DecorationLayerChromium.cpp
diff --git a/cc/DecorationLayerChromium.cpp b/cc/DecorationLayerChromium.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..8db0317e9d1e7b0e41f6aa80d9a93083ce84ba3b
--- /dev/null
+++ b/cc/DecorationLayerChromium.cpp
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if USE(ACCELERATED_COMPOSITING)
+
+#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, PassOwnPtr<CCPrioritizedTexture> texture)
+ : LayerTextureUpdater::Texture(texture)
+ , m_textureUpdater(textureUpdater)
+ {
+ }
+
+ virtual void updateRect(CCResourceProvider* resourceProvider, const IntRect& sourceRect, const IntSize& destOffset) OVERRIDE
+ {
+ textureUpdater()->updateTextureRect(resourceProvider, texture(), sourceRect, destOffset);
+ }
+
+ 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)
+ {
+ OwnPtr<CCPrioritizedTexture> texture = CCPrioritizedTexture::create(manager);
+ ASSERT(!m_bitmap.isNull());
+ texture->setDimensions(IntSize(m_bitmap.width(), m_bitmap.height()),GraphicsContext3D::RGBA);
+ texture->setRequestPriority(CCPriorityCalculator::uiPriority(true));
+ return adoptPtr(new Texture(this, texture.release()));
+ }
+
+ virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRIDE
+ {
+ return PlatformColor::sameComponentOrder(textureFormat) ?
+ LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdater::SampledTexelFormatBGRA;
+ }
+
+ void updateTextureRect(CCResourceProvider* resourceProvider, CCPrioritizedTexture* texture, const IntRect& sourceRect, const IntSize& destOffset)
+ {
+ ASSERT(sourceRect == IntRect(0, 0, m_bitmap.width(), m_bitmap.height()));
+ SkAutoLockPixels lock(m_bitmap);
+ texture->upload(resourceProvider, static_cast<const uint8_t*>(m_bitmap.getPixels()), sourceRect, sourceRect, destOffset);
+ }
+
+ void setBitmap(const SkBitmap& bitmap)
+ {
+ m_bitmap = bitmap;
+ }
+
+private:
+ DecorationLayerTextureUpdater() { }
+ SkBitmap m_bitmap;
+};
+
+PassRefPtr<DecorationLayerChromium> DecorationLayerChromium::create()
+{
+ return adoptRef(new DecorationLayerChromium());
+}
+
+DecorationLayerChromium::DecorationLayerChromium()
+ : LayerChromium()
+{
+}
+
+DecorationLayerChromium::~DecorationLayerChromium()
+{
+}
+
+PassOwnPtr<CCLayerImpl> DecorationLayerChromium::createCCLayerImpl()
+{
+ return CCDecorationLayerImpl::create(id());
+}
+
+void DecorationLayerChromium::setTexturePriorities(const CCPriorityCalculator& priorityCalc)
+{
+ if (!m_bitmap.isNull() && !m_texture.get()) {
+ createTextureUpdaterIfNeeded();
+ m_textureUpdater->setBitmap(m_bitmap);
+ m_needsDisplay = false;
+ m_texture = m_textureUpdater->createTexture(layerTreeHost()->contentsTextureManager());
+ }
+}
+
+void DecorationLayerChromium::setBitmap(const SkBitmap& bitmap, const IntRect& aperture) {
+ m_bitmap = bitmap;
+ m_imageAperture = aperture;
+ setNeedsDisplay();
+}
+
+void DecorationLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclusionTracker* occlusion, CCRenderingStats& stats)
+{
+ createTextureUpdaterIfNeeded();
+
+ IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bitmap.height()));
+
+ ASSERT(m_texture.get());
+ TextureUploader::Parameters upload = { m_texture.get(), contentRect, IntSize() };
+ queue.appendFullUpload(upload);
+}
+
+void DecorationLayerChromium::createTextureUpdaterIfNeeded()
+{
+ if (m_textureUpdater)
+ return;
+
+ m_textureUpdater = DecorationLayerTextureUpdater::create();
+}
+
+bool DecorationLayerChromium::drawsContent() const
+{
+ bool draws = !m_bitmap.isNull() && LayerChromium::drawsContent();
+ return draws;
+}
+
+bool DecorationLayerChromium::needsContentsScale() const
+{
+ return false;
+}
+
+void DecorationLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
+{
+ LayerChromium::pushPropertiesTo(layer);
+ CCDecorationLayerImpl* layerImpl = static_cast<CCDecorationLayerImpl*>(layer);
+
+ layerImpl->setResourceId(m_texture->texture()->resourceId());
+ layerImpl->setDecorationLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
+}
+
+}
+#endif // USE(ACCELERATED_COMPOSITING)

Powered by Google App Engine
This is Rietveld 408576698