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

Side by Side Diff: cc/nine_patch_layer_impl.cc

Issue 11304020: cc: Nine patch layer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add unit tests and address code review Created 8 years, 1 month 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
OLDNEW
(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 #include "ui/gfx/rect_f.h"
12
13 namespace cc {
14
15 NinePatchLayerImpl::NinePatchLayerImpl(int id)
16 : LayerImpl(id)
17 , m_resourceId(0)
18 {
19 }
20
21 NinePatchLayerImpl::~NinePatchLayerImpl()
22 {
23 }
24
25 ResourceProvider::ResourceId NinePatchLayerImpl::contentsResourceId() const
26 {
27 return 0;
28 }
29
30 void NinePatchLayerImpl::dumpLayerProperties(std::string* str, int indent) const
31 {
32 LayerImpl::dumpLayerProperties(str, indent);
33 }
34
35
36 void NinePatchLayerImpl::willDraw(ResourceProvider* resourceProvider)
37 {
38 }
39
40 static gfx::RectF normalizedRect(float x, float y, float width, float height, fl oat totalWidth, float totalHeight)
41 {
42 return gfx::RectF(x / totalWidth, y / totalHeight, width / totalWidth, heigh t / totalHeight);
43 }
44
45 void NinePatchLayerImpl::setLayout(const gfx::Size& imageBounds, const gfx::Rect & aperture)
46 {
47 m_imageBounds = imageBounds;
48 m_imageAperture = aperture;
49 }
50
51 void NinePatchLayerImpl::appendQuads(QuadSink& quadSink, AppendQuadsData& append QuadsData)
52 {
53 if (!m_resourceId)
54 return;
55
56 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSharedQ uadState());
57 appendDebugBorderQuad(quadSink, sharedQuadState, appendQuadsData);
58
59 static const bool flipped = false;
60 static const bool premultipliedAlpha = true;
61
62 DCHECK(!bounds().IsEmpty());
63
64 // NinePatch border widths in image space
65 int leftWidth = m_imageAperture.x();
66 int topHeight = m_imageAperture.y();
67 int rightWidth = m_imageBounds.width() - m_imageAperture.right();
68 int bottomHeight = m_imageBounds.height() - m_imageAperture.bottom();
69
70 gfx::Rect topLeft(0, 0, leftWidth, topHeight);
71 gfx::Rect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight);
72 gfx::Rect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomH eight);
73 gfx::Rect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight );
74 gfx::Rect top(topLeft.right(), 0, bounds().width() - leftWidth - rightWidth, topHeight);
75 gfx::Rect left(0, topLeft.bottom(), leftWidth, bounds().height() - topHeight - bottomHeight);
76 gfx::Rect right(topRight.x(), topRight.bottom(), rightWidth, left.height());
77 gfx::Rect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight);
78
79 float imgWidth = m_imageBounds.width();
80 float imgHeight = m_imageBounds.height();
81
82 gfx::RectF uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, imgHeight);
jamesr 2012/11/05 23:10:53 I think some comments here indicating how the uv r
aelias_OOO_until_Jul13 2012/11/06 01:15:00 I added a comment in NinePatchLayer.h as the inten
83 gfx::RectF uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth, topHeight, imgWidth, imgHeight);
84 gfx::RectF uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWi dth, bottomHeight, imgWidth, imgHeight);
85 gfx::RectF uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight - bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight);
86 gfx::RectF uvTop(uvTopLeft.right(), 0, (imgWidth - leftWidth - rightWidth) / imgWidth, (topHeight) / imgHeight);
87 gfx::RectF uvLeft(0, uvTopLeft.bottom(), leftWidth / imgWidth, (imgHeight - topHeight - bottomHeight) / imgHeight);
88 gfx::RectF uvRight(uvTopRight.x(), uvTopRight.bottom(), rightWidth / imgWidt h, uvLeft.height());
89 gfx::RectF uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight / imgHeight);
90
91 quadSink.append(TextureDrawQuad::create(sharedQuadState, topLeft, m_resource Id, premultipliedAlpha, uvTopLeft, flipped).PassAs<DrawQuad>(), appendQuadsData) ;
92 quadSink.append(TextureDrawQuad::create(sharedQuadState, topRight, m_resourc eId, premultipliedAlpha, uvTopRight, flipped).PassAs<DrawQuad>(), appendQuadsDat a);
93 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomLeft, m_resou rceId, premultipliedAlpha, uvBottomLeft, flipped).PassAs<DrawQuad>(), appendQuad sData);
94 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomRight, m_reso urceId, premultipliedAlpha, uvBottomRight, flipped).PassAs<DrawQuad>(), appendQu adsData);
95 quadSink.append(TextureDrawQuad::create(sharedQuadState, top, m_resourceId, premultipliedAlpha, uvTop, flipped).PassAs<DrawQuad>(), appendQuadsData);
96 quadSink.append(TextureDrawQuad::create(sharedQuadState, left, m_resourceId, premultipliedAlpha, uvLeft, flipped).PassAs<DrawQuad>(), appendQuadsData);
97 quadSink.append(TextureDrawQuad::create(sharedQuadState, right, m_resourceId , premultipliedAlpha, uvRight, flipped).PassAs<DrawQuad>(), appendQuadsData);
98 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottom, m_resourceI d, premultipliedAlpha, uvBottom, flipped).PassAs<DrawQuad>(), appendQuadsData);
99 }
100
101 void NinePatchLayerImpl::didDraw(ResourceProvider* resourceProvider)
102 {
103 }
104
105 void NinePatchLayerImpl::didLoseContext()
106 {
107 m_resourceId = 0;
108 }
109
110 const char* NinePatchLayerImpl::layerTypeAsString() const
111 {
112 return "NinePatchLayer";
113 }
114
115 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698