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

Side by Side 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, 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27
28 #if USE(ACCELERATED_COMPOSITING)
29
30 #include "CCDecorationLayerImpl.h"
31
32 #include "CCQuadSink.h"
33 #include "CCTextureDrawQuad.h"
34
35 namespace cc {
36
37 CCDecorationLayerImpl::CCDecorationLayerImpl(int id)
38 : CCLayerImpl(id)
39 , m_resourceId(0)
40 {
41 }
42
43 CCDecorationLayerImpl::~CCDecorationLayerImpl()
44 {
45 }
46
47 CCResourceProvider::ResourceId CCDecorationLayerImpl::contentsResourceId() const
48 {
49 return 0;
50 }
51
52 void CCDecorationLayerImpl::dumpLayerProperties(std::string* str, int indent) co nst
53 {
54 CCLayerImpl::dumpLayerProperties(str, indent);
55 }
56
57
58 void CCDecorationLayerImpl::willDraw(CCResourceProvider* resourceProvider)
59 {
60 }
61
62 static FloatRect normalizedRect(float x, float y, float width, float height, flo at totalWidth, float totalHeight)
63 {
64 return FloatRect(x / totalWidth, y / totalHeight, width / totalWidth, height / totalHeight);
65 }
66
67 void CCDecorationLayerImpl::setDecorationLayout(const IntSize& imageBounds, cons t IntRect& aperture)
68 {
69 m_imageBounds = imageBounds;
70 m_imageAperture = aperture;
71 }
72
73 void CCDecorationLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData& appendQuadsData)
74 {
75 if (!m_resourceId)
76 return;
77
78 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare dQuadState());
79 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
80
81 bool flipped = false;
82 bool premultipliedAlpha = true;
83
84 /*if (1) {
85 IntRect quadRect(IntPoint(), contentBounds());
86 FloatRect uvRect(0, 0, 1, 1);
87 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, quadRect, m_res ourceId, premultipliedAlpha, uvRect, flipped), appendQuadsData);
88 return;
89 } */
90
91 ASSERT(!bounds().isEmpty() && !m_imageBounds.isEmpty());
92
93 // decoration border widths in image space
94 int leftWidth = m_imageAperture.x();
95 int topHeight = m_imageAperture.y();
96 int rightWidth = m_imageBounds.width() - m_imageAperture.maxX();
97 int bottomHeight = m_imageBounds.height() - m_imageAperture.maxY();
98
99 IntRect topLeft(0, 0, leftWidth, topHeight);
100 IntRect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight);
101 IntRect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomHei ght);
102 IntRect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight);
103 IntRect top(topLeft.maxX(), 0, bounds().width() - leftWidth - rightWidth, to pHeight);
104 IntRect left(0, topLeft.maxY(), leftWidth, bounds().height() - topHeight - b ottomHeight);
105 IntRect right(topRight.x(), topRight.maxY(), rightWidth, left.height());
106 IntRect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight);
107
108 float imgWidth = m_imageBounds.width();
109 float imgHeight = m_imageBounds.height();
110
111 FloatRect uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, i mgHeight);
112 FloatRect uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth, topHeight, imgWidth, imgHeight);
113 FloatRect uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWid th, bottomHeight, imgWidth, imgHeight);
114 FloatRect uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight - bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight);
115 FloatRect uvTop(uvTopLeft.maxX(), 0, (imgWidth - leftWidth - rightWidth) / i mgWidth, (topHeight) / imgHeight);
116 FloatRect uvLeft(0, uvTopLeft.maxY(), leftWidth / imgWidth, (imgHeight - top Height - bottomHeight) / imgHeight);
117 FloatRect uvRight(uvTopRight.x(), uvTopRight.maxY(), rightWidth / imgWidth, uvLeft.height());
118 FloatRect uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight / imgHeight);
119
120 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topLeft, m_resour ceId, premultipliedAlpha, uvTopLeft, flipped), appendQuadsData);
121 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topRight, m_resou rceId, premultipliedAlpha, uvTopRight, flipped), appendQuadsData);
122 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomLeft, m_res ourceId, premultipliedAlpha, uvBottomLeft, flipped), appendQuadsData);
123 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomRight, m_re sourceId, premultipliedAlpha, uvBottomRight, flipped), appendQuadsData);
124 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, top, m_resourceId , premultipliedAlpha, uvTop, flipped), appendQuadsData);
125 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, left, m_resourceI d, premultipliedAlpha, uvLeft, flipped), appendQuadsData);
126 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, right, m_resource Id, premultipliedAlpha, uvRight, flipped), appendQuadsData);
127 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottom, m_resourc eId, premultipliedAlpha, uvBottom, flipped), appendQuadsData);
128 }
129
130 void CCDecorationLayerImpl::didDraw(CCResourceProvider* resourceProvider)
131 {
132 }
133
134 Region CCDecorationLayerImpl::visibleContentOpaqueRegion() const
135 {
136 if (opaque())
137 return visibleContentRect();
138 return Region();
139 }
140
141 void CCDecorationLayerImpl::didLoseContext()
142 {
143 m_resourceId = 0;
144 }
145
146 } // namespace WebCore
147
148 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698