OLD | NEW |
(Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "CCDecorationLayerImpl.h" |
| 8 |
| 9 #include "CCQuadSink.h" |
| 10 #include "CCTextureDrawQuad.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 CCDecorationLayerImpl::CCDecorationLayerImpl(int id) |
| 15 : CCLayerImpl(id) |
| 16 , m_resourceId(0) |
| 17 { |
| 18 } |
| 19 |
| 20 CCDecorationLayerImpl::~CCDecorationLayerImpl() |
| 21 { |
| 22 } |
| 23 |
| 24 CCResourceProvider::ResourceId CCDecorationLayerImpl::contentsResourceId() const |
| 25 { |
| 26 return 0; |
| 27 } |
| 28 |
| 29 void CCDecorationLayerImpl::dumpLayerProperties(std::string* str, int indent) co
nst |
| 30 { |
| 31 CCLayerImpl::dumpLayerProperties(str, indent); |
| 32 } |
| 33 |
| 34 |
| 35 void CCDecorationLayerImpl::willDraw(CCResourceProvider* resourceProvider) |
| 36 { |
| 37 } |
| 38 |
| 39 static FloatRect normalizedRect(float x, float y, float width, float height, flo
at totalWidth, float totalHeight) |
| 40 { |
| 41 return FloatRect(x / totalWidth, y / totalHeight, width / totalWidth, height
/ totalHeight); |
| 42 } |
| 43 |
| 44 void CCDecorationLayerImpl::setDecorationLayout(const IntSize& imageBounds, cons
t IntRect& aperture) |
| 45 { |
| 46 m_imageBounds = imageBounds; |
| 47 m_imageAperture = aperture; |
| 48 } |
| 49 |
| 50 void CCDecorationLayerImpl::appendQuads(CCQuadSink& quadSink, CCAppendQuadsData&
appendQuadsData) |
| 51 { |
| 52 if (!m_resourceId) |
| 53 return; |
| 54 |
| 55 CCSharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createShare
dQuadState()); |
| 56 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
| 57 |
| 58 static const bool flipped = false; |
| 59 static const bool premultipliedAlpha = true; |
| 60 |
| 61 ASSERT(!bounds().isEmpty()); |
| 62 |
| 63 // decoration border widths in image space |
| 64 int leftWidth = m_imageAperture.x(); |
| 65 int topHeight = m_imageAperture.y(); |
| 66 int rightWidth = m_imageBounds.width() - m_imageAperture.maxX(); |
| 67 int bottomHeight = m_imageBounds.height() - m_imageAperture.maxY(); |
| 68 |
| 69 IntRect topLeft(0, 0, leftWidth, topHeight); |
| 70 IntRect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight); |
| 71 IntRect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomHei
ght); |
| 72 IntRect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight); |
| 73 IntRect top(topLeft.maxX(), 0, bounds().width() - leftWidth - rightWidth, to
pHeight); |
| 74 IntRect left(0, topLeft.maxY(), leftWidth, bounds().height() - topHeight - b
ottomHeight); |
| 75 IntRect right(topRight.x(), topRight.maxY(), rightWidth, left.height()); |
| 76 IntRect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight); |
| 77 |
| 78 float imgWidth = m_imageBounds.width(); |
| 79 float imgHeight = m_imageBounds.height(); |
| 80 |
| 81 FloatRect uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, i
mgHeight); |
| 82 FloatRect uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth,
topHeight, imgWidth, imgHeight); |
| 83 FloatRect uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWid
th, bottomHeight, imgWidth, imgHeight); |
| 84 FloatRect uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight -
bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight); |
| 85 FloatRect uvTop(uvTopLeft.maxX(), 0, (imgWidth - leftWidth - rightWidth) / i
mgWidth, (topHeight) / imgHeight); |
| 86 FloatRect uvLeft(0, uvTopLeft.maxY(), leftWidth / imgWidth, (imgHeight - top
Height - bottomHeight) / imgHeight); |
| 87 FloatRect uvRight(uvTopRight.x(), uvTopRight.maxY(), rightWidth / imgWidth,
uvLeft.height()); |
| 88 FloatRect uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight
/ imgHeight); |
| 89 |
| 90 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topLeft, m_resour
ceId, premultipliedAlpha, uvTopLeft, flipped).PassAs<CCDrawQuad>(), appendQuadsD
ata); |
| 91 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, topRight, m_resou
rceId, premultipliedAlpha, uvTopRight, flipped).PassAs<CCDrawQuad>(), appendQuad
sData); |
| 92 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomLeft, m_res
ourceId, premultipliedAlpha, uvBottomLeft, flipped).PassAs<CCDrawQuad>(), append
QuadsData); |
| 93 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottomRight, m_re
sourceId, premultipliedAlpha, uvBottomRight, flipped).PassAs<CCDrawQuad>(), appe
ndQuadsData); |
| 94 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, top, m_resourceId
, premultipliedAlpha, uvTop, flipped).PassAs<CCDrawQuad>(), appendQuadsData); |
| 95 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, left, m_resourceI
d, premultipliedAlpha, uvLeft, flipped).PassAs<CCDrawQuad>(), appendQuadsData); |
| 96 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, right, m_resource
Id, premultipliedAlpha, uvRight, flipped).PassAs<CCDrawQuad>(), appendQuadsData)
; |
| 97 quadSink.append(CCTextureDrawQuad::create(sharedQuadState, bottom, m_resourc
eId, premultipliedAlpha, uvBottom, flipped).PassAs<CCDrawQuad>(), appendQuadsDat
a); |
| 98 } |
| 99 |
| 100 void CCDecorationLayerImpl::didDraw(CCResourceProvider* resourceProvider) |
| 101 { |
| 102 } |
| 103 |
| 104 void CCDecorationLayerImpl::didLoseContext() |
| 105 { |
| 106 m_resourceId = 0; |
| 107 } |
| 108 |
| 109 } // namespace WebCore |
OLD | NEW |