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 "nine_patch_layer_impl.h" |
| 8 |
| 9 #include "cc/quad_sink.h" |
| 10 #include "cc/texture_draw_quad.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 NinePatchLayerImpl::NinePatchLayerImpl(int id) |
| 15 : LayerImpl(id) |
| 16 , m_resourceId(0) |
| 17 { |
| 18 } |
| 19 |
| 20 NinePatchLayerImpl::~NinePatchLayerImpl() |
| 21 { |
| 22 } |
| 23 |
| 24 ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const |
| 25 { |
| 26 return 0; |
| 27 } |
| 28 |
| 29 void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) const |
| 30 { |
| 31 LayerImpl::dumpLayerProperties(str, indent); |
| 32 } |
| 33 |
| 34 |
| 35 void NinePatchLayerImpl::willDraw(ResourceProvider* 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 NinePatchLayerImpl::setNinePatchLayout(const IntSize& imageBounds, const In
tRect& aperture) |
| 45 { |
| 46 m_imageBounds = imageBounds; |
| 47 m_imageAperture = aperture; |
| 48 } |
| 49 |
| 50 void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append
QuadsData) |
| 51 { |
| 52 if (!m_resourceId) |
| 53 return; |
| 54 |
| 55 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ
uadState()); |
| 56 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData); |
| 57 |
| 58 static const bool flipped = false; |
| 59 static const bool premultipliedAlpha = true; |
| 60 |
| 61 DCHECK(!bounds().isEmpty()); |
| 62 |
| 63 // NinePatch 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(TextureDrawQuad::create(sharedQuadState, topLeft, m_resource
Id, premultipliedAlpha, uvTopLeft, flipped).PassAs<DrawQuad>(), appendQuadsData)
; |
| 91 quadSink.append(TextureDrawQuad::create(sharedQuadState, topRight, m_resourc
eId, premultipliedAlpha, uvTopRight, flipped).PassAs<DrawQuad>(), appendQuadsDat
a); |
| 92 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomLeft, m_resou
rceId, premultipliedAlpha, uvBottomLeft, flipped).PassAs<DrawQuad>(), appendQuad
sData); |
| 93 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomRight, m_reso
urceId, premultipliedAlpha, uvBottomRight, flipped).PassAs<DrawQuad>(), appendQu
adsData); |
| 94 quadSink.append(TextureDrawQuad::create(sharedQuadState, top, m_resourceId,
premultipliedAlpha, uvTop, flipped).PassAs<DrawQuad>(), appendQuadsData); |
| 95 quadSink.append(TextureDrawQuad::create(sharedQuadState, left, m_resourceId,
premultipliedAlpha, uvLeft, flipped).PassAs<DrawQuad>(), appendQuadsData); |
| 96 quadSink.append(TextureDrawQuad::create(sharedQuadState, right, m_resourceId
, premultipliedAlpha, uvRight, flipped).PassAs<DrawQuad>(), appendQuadsData); |
| 97 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottom, m_resourceI
d, premultipliedAlpha, uvBottom, flipped).PassAs<DrawQuad>(), appendQuadsData); |
| 98 } |
| 99 |
| 100 void NinePatchLayerImpl::didDraw(ResourceProvider* resourceProvider) |
| 101 { |
| 102 } |
| 103 |
| 104 void NinePatchLayerImpl::didLoseContext() |
| 105 { |
| 106 m_resourceId = 0; |
| 107 } |
| 108 |
| 109 const char* NinePatchLayerImpl::layerTypeAsString() const |
| 110 { |
| 111 return "NinePatchLayer"; |
| 112 } |
| 113 |
| 114 } |
OLD | NEW |