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

Unified Diff: cc/CCDecorationLayerImpl.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/CCDecorationLayerImpl.cpp
diff --git a/cc/CCDecorationLayerImpl.cpp b/cc/CCDecorationLayerImpl.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a02236237e8c2a5feb41c289bdc61da62ea836fb
--- /dev/null
+++ b/cc/CCDecorationLayerImpl.cpp
@@ -0,0 +1,148 @@
+/*
+ * 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:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS 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 APPLE OR ITS 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 "CCDecorationLayerImpl.h"
+
+#include "CCQuadSink.h"
+#include "CCTextureDrawQuad.h"
+
+namespace cc {
+
+CCDecorationLayerImpl::CCDecorationLayerImpl(int id)
+ : CCLayerImpl(id)
+ , m_resourceId(0)
+{
+}
+
+CCDecorationLayerImpl::~CCDecorationLayerImpl()
+{
+}
+
+CCResourceProvider::ResourceId CCDecorationLayerImpl::contentsResourceId() const
+{
+ return 0;
+}
+
+void CCDecorationLayerImpl::dumpLayerProperties(std::string* str, int indent) const
+{
+ CCLayerImpl::dumpLayerProperties(str, indent);
+}
+
+
+void CCDecorationLayerImpl::willDraw(CCResourceProvider* resourceProvider)
+{
+}
+
+static FloatRect normalizedRect(float x, float y, float width, float height, float totalWidth, float totalHeight)
+{
+ return FloatRect(x / totalWidth, y / totalHeight, width / totalWidth, height / totalHeight);
+}
+
+void CCDecorationLayerImpl::setDecorationLayout(const IntSize& imageBounds, const IntRect& aperture)
+{
+ m_imageBounds = imageBounds;
+ m_imageAperture = aperture;
+}
+
+void CCDecorationLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuadsData)
+{
+ if (!m_resourceId)
+ return;
+
+ CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
+ appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
+
+ bool flipped = false;
+ bool premultipliedAlpha = true;
+
+ /*if (1) {
+ IntRect quadRect(IntPoint(), contentBounds());
+ FloatRect uvRect(0, 0, 1, 1);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, quadRect, m_resourceId, premultipliedAlpha, uvRect, flipped), appendQuadsData);
+ return;
+ } */
+
+ ASSERT(!bounds().isEmpty() && !m_imageBounds.isEmpty());
+
+ // decoration border widths in image space
+ int leftWidth = m_imageAperture.x();
+ int topHeight = m_imageAperture.y();
+ int rightWidth = m_imageBounds.width() - m_imageAperture.maxX();
+ int bottomHeight = m_imageBounds.height() - m_imageAperture.maxY();
+
+ IntRect topLeft(0, 0, leftWidth, topHeight);
+ IntRect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight);
+ IntRect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomHeight);
+ IntRect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight);
+ IntRect top(topLeft.maxX(), 0, bounds().width() - leftWidth - rightWidth, topHeight);
+ IntRect left(0, topLeft.maxY(), leftWidth, bounds().height() - topHeight - bottomHeight);
+ IntRect right(topRight.x(), topRight.maxY(), rightWidth, left.height());
+ IntRect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight);
+
+ float imgWidth = m_imageBounds.width();
+ float imgHeight = m_imageBounds.height();
+
+ FloatRect uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, imgHeight);
+ FloatRect uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth, topHeight, imgWidth, imgHeight);
+ FloatRect uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWidth, bottomHeight, imgWidth, imgHeight);
+ FloatRect uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight - bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight);
+ FloatRect uvTop(uvTopLeft.maxX(), 0, (imgWidth - leftWidth - rightWidth) / imgWidth, (topHeight) / imgHeight);
+ FloatRect uvLeft(0, uvTopLeft.maxY(), leftWidth / imgWidth, (imgHeight - topHeight - bottomHeight) / imgHeight);
+ FloatRect uvRight(uvTopRight.x(), uvTopRight.maxY(), rightWidth / imgWidth, uvLeft.height());
+ FloatRect uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight / imgHeight);
+
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topLeft, m_resourceId, premultipliedAlpha, uvTopLeft, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topRight, m_resourceId, premultipliedAlpha, uvTopRight, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomLeft, m_resourceId, premultipliedAlpha, uvBottomLeft, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomRight, m_resourceId, premultipliedAlpha, uvBottomRight, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, top, m_resourceId, premultipliedAlpha, uvTop, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, left, m_resourceId, premultipliedAlpha, uvLeft, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, right, m_resourceId, premultipliedAlpha, uvRight, flipped), appendQuadsData);
+ quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottom, m_resourceId, premultipliedAlpha, uvBottom, flipped), appendQuadsData);
+}
+
+void CCDecorationLayerImpl::didDraw(CCResourceProvider* resourceProvider)
+{
+}
+
+Region CCDecorationLayerImpl::visibleContentOpaqueRegion() const
+{
+ if (opaque())
+ return visibleContentRect();
+ return Region();
+}
+
+void CCDecorationLayerImpl::didLoseContext()
+{
+ m_resourceId = 0;
+}
+
+} // namespace WebCore
+
+#endif // USE(ACCELERATED_COMPOSITING)

Powered by Google App Engine
This is Rietveld 408576698