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

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: Fix DCHECK failures and rebase to 166129 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
« no previous file with comments | « cc/nine_patch_layer_impl.h ('k') | cc/nine_patch_layer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 bitmap pixel 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 // Patch positions in layer space
71 gfx::Rect topLeft(0, 0, leftWidth, topHeight);
72 gfx::Rect topRight(bounds().width() - rightWidth, 0, rightWidth, topHeight);
73 gfx::Rect bottomLeft(0, bounds().height() - bottomHeight, leftWidth, bottomH eight);
74 gfx::Rect bottomRight(topRight.x(), bottomLeft.y(), rightWidth, bottomHeight );
75 gfx::Rect top(topLeft.right(), 0, bounds().width() - leftWidth - rightWidth, topHeight);
76 gfx::Rect left(0, topLeft.bottom(), leftWidth, bounds().height() - topHeight - bottomHeight);
77 gfx::Rect right(topRight.x(), topRight.bottom(), rightWidth, left.height());
78 gfx::Rect bottom(top.x(), bottomLeft.y(), top.width(), bottomHeight);
79
80 float imgWidth = m_imageBounds.width();
81 float imgHeight = m_imageBounds.height();
82
83 // Patch positions in bitmap UV space (from zero to one)
84 gfx::RectF uvTopLeft = normalizedRect(0, 0, leftWidth, topHeight, imgWidth, imgHeight);
85 gfx::RectF uvTopRight = normalizedRect(imgWidth - rightWidth, 0, rightWidth, topHeight, imgWidth, imgHeight);
86 gfx::RectF uvBottomLeft = normalizedRect(0, imgHeight - bottomHeight, leftWi dth, bottomHeight, imgWidth, imgHeight);
87 gfx::RectF uvBottomRight = normalizedRect(imgWidth - rightWidth, imgHeight - bottomHeight, rightWidth, bottomHeight, imgWidth, imgHeight);
88 gfx::RectF uvTop(uvTopLeft.right(), 0, (imgWidth - leftWidth - rightWidth) / imgWidth, (topHeight) / imgHeight);
89 gfx::RectF uvLeft(0, uvTopLeft.bottom(), leftWidth / imgWidth, (imgHeight - topHeight - bottomHeight) / imgHeight);
90 gfx::RectF uvRight(uvTopRight.x(), uvTopRight.bottom(), rightWidth / imgWidt h, uvLeft.height());
91 gfx::RectF uvBottom(uvTop.x(), uvBottomLeft.y(), uvTop.width(), bottomHeight / imgHeight);
92
93 quadSink.append(TextureDrawQuad::create(sharedQuadState, topLeft, m_resource Id, premultipliedAlpha, uvTopLeft, flipped).PassAs<DrawQuad>(), appendQuadsData) ;
94 quadSink.append(TextureDrawQuad::create(sharedQuadState, topRight, m_resourc eId, premultipliedAlpha, uvTopRight, flipped).PassAs<DrawQuad>(), appendQuadsDat a);
95 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomLeft, m_resou rceId, premultipliedAlpha, uvBottomLeft, flipped).PassAs<DrawQuad>(), appendQuad sData);
96 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottomRight, m_reso urceId, premultipliedAlpha, uvBottomRight, flipped).PassAs<DrawQuad>(), appendQu adsData);
97 quadSink.append(TextureDrawQuad::create(sharedQuadState, top, m_resourceId, premultipliedAlpha, uvTop, flipped).PassAs<DrawQuad>(), appendQuadsData);
98 quadSink.append(TextureDrawQuad::create(sharedQuadState, left, m_resourceId, premultipliedAlpha, uvLeft, flipped).PassAs<DrawQuad>(), appendQuadsData);
99 quadSink.append(TextureDrawQuad::create(sharedQuadState, right, m_resourceId , premultipliedAlpha, uvRight, flipped).PassAs<DrawQuad>(), appendQuadsData);
100 quadSink.append(TextureDrawQuad::create(sharedQuadState, bottom, m_resourceI d, premultipliedAlpha, uvBottom, flipped).PassAs<DrawQuad>(), appendQuadsData);
101 }
102
103 void NinePatchLayerImpl::didDraw(ResourceProvider* resourceProvider)
104 {
105 }
106
107 void NinePatchLayerImpl::didLoseContext()
108 {
109 m_resourceId = 0;
110 }
111
112 const char* NinePatchLayerImpl::layerTypeAsString() const
113 {
114 return "NinePatchLayer";
115 }
116
117 }
OLDNEW
« no previous file with comments | « cc/nine_patch_layer_impl.h ('k') | cc/nine_patch_layer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698