| Index: cc/nine_patch_layer_impl.cc
|
| diff --git a/cc/nine_patch_layer_impl.cc b/cc/nine_patch_layer_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7a60c877492ad0682eb5d5f55b8d1dfbf8c82b61
|
| --- /dev/null
|
| +++ b/cc/nine_patch_layer_impl.cc
|
| @@ -0,0 +1,114 @@
|
| +// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "config.h"
|
| +
|
| +#include "nine_patch_layer_impl.h"
|
| +
|
| +#include "cc/quad_sink.h"
|
| +#include "cc/texture_draw_quad.h"
|
| +
|
| +namespace cc {
|
| +
|
| +NinePatchLayerImpl::NinePatchLayerImpl(int id)
|
| + : LayerImpl(id)
|
| + , m_resourceId(0)
|
| +{
|
| +}
|
| +
|
| +NinePatchLayerImpl::~NinePatchLayerImpl()
|
| +{
|
| +}
|
| +
|
| +ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const
|
| +{
|
| + return 0;
|
| +}
|
| +
|
| +void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) const
|
| +{
|
| + LayerImpl::dumpLayerProperties(str, indent);
|
| +}
|
| +
|
| +
|
| +void NinePatchLayerImpl::willDraw(ResourceProvider* 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 NinePatchLayerImpl::setNinePatchLayout(const IntSize& imageBounds, const IntRect& aperture)
|
| +{
|
| + m_imageBounds = imageBounds;
|
| + m_imageAperture = aperture;
|
| +}
|
| +
|
| +void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& appendQuadsData)
|
| +{
|
| + if (!m_resourceId)
|
| + return;
|
| +
|
| + SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQuadState());
|
| + appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
|
| +
|
| + static const bool flipped = false;
|
| + static const bool premultipliedAlpha = true;
|
| +
|
| + DCHECK(!bounds().isEmpty());
|
| +
|
| + // NinePatch 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(TextureDrawQuad::create(sharedQuadState, topLeft, m_resourceId, premultipliedAlpha, uvTopLeft, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, topRight, m_resourceId, premultipliedAlpha, uvTopRight, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomLeft, m_resourceId, premultipliedAlpha, uvBottomLeft, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomRight, m_resourceId, premultipliedAlpha, uvBottomRight, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, top, m_resourceId, premultipliedAlpha, uvTop, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, left, m_resourceId, premultipliedAlpha, uvLeft, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, right, m_resourceId, premultipliedAlpha, uvRight, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| + quadSink.append(TextureDrawQuad::create(sharedQuadState, bottom, m_resourceId, premultipliedAlpha, uvBottom, flipped).PassAs<DrawQuad>(), appendQuadsData);
|
| +}
|
| +
|
| +void NinePatchLayerImpl::didDraw(ResourceProvider* resourceProvider)
|
| +{
|
| +}
|
| +
|
| +void NinePatchLayerImpl::didLoseContext()
|
| +{
|
| + m_resourceId = 0;
|
| +}
|
| +
|
| +const char* NinePatchLayerImpl::layerTypeAsString() const
|
| +{
|
| + return "NinePatchLayer";
|
| +}
|
| +
|
| +}
|
|
|