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

Side by Side Diff: cc/DecorationLayerChromium.cpp

Issue 10963056: [cc] Add window decoration layers (NinePatch) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31 #include "config.h"
32
33 #if USE(ACCELERATED_COMPOSITING)
34
35 #include "DecorationLayerChromium.h"
36
37 #include "CCLayerTreeHost.h"
38 #include "CCDecorationLayerImpl.h"
39 #include "CCTextureUpdateQueue.h"
40 #include "LayerTextureUpdater.h"
41 #include "PlatformColor.h"
42 #include "TextureUploader.h"
43
44 namespace cc {
45
46 class DecorationLayerTextureUpdater : public LayerTextureUpdater {
47 public:
48 class Texture : public LayerTextureUpdater::Texture {
49 public:
50 Texture(DecorationLayerTextureUpdater* textureUpdater, PassOwnPtr<CCPrio ritizedTexture> texture)
51 : LayerTextureUpdater::Texture(texture)
52 , m_textureUpdater(textureUpdater)
53 {
54 }
55
56 virtual void updateRect(CCResourceProvider* resourceProvider, const IntR ect& sourceRect, const IntSize& destOffset) OVERRIDE
57 {
58 textureUpdater()->updateTextureRect(resourceProvider, texture(), sou rceRect, destOffset);
59 }
60
61 private:
62 DecorationLayerTextureUpdater* textureUpdater() { return m_textureUpdate r; }
63
64 DecorationLayerTextureUpdater* m_textureUpdater;
65 };
66
67 static PassRefPtr<DecorationLayerTextureUpdater> create()
68 {
69 return adoptRef(new DecorationLayerTextureUpdater());
70 }
71
72 virtual ~DecorationLayerTextureUpdater() { }
73
74 virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(CCPrioritized TextureManager* manager)
75 {
76 OwnPtr<CCPrioritizedTexture> texture = CCPrioritizedTexture::create(mana ger);
77 ASSERT(!m_bitmap.isNull());
78 texture->setDimensions(IntSize(m_bitmap.width(), m_bitmap.height()),Grap hicsContext3D::RGBA);
79 texture->setRequestPriority(CCPriorityCalculator::uiPriority(true));
80 return adoptPtr(new Texture(this, texture.release()));
81 }
82
83 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRI DE
84 {
85 return PlatformColor::sameComponentOrder(textureFormat) ?
86 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdate r::SampledTexelFormatBGRA;
87 }
88
89 void updateTextureRect(CCResourceProvider* resourceProvider, CCPrioritizedTe xture* texture, const IntRect& sourceRect, const IntSize& destOffset)
90 {
91 ASSERT(sourceRect == IntRect(0, 0, m_bitmap.width(), m_bitmap.height())) ;
92 SkAutoLockPixels lock(m_bitmap);
93 texture->upload(resourceProvider, static_cast<const uint8_t*>(m_bitmap.g etPixels()), sourceRect, sourceRect, destOffset);
94 }
95
96 void setBitmap(const SkBitmap& bitmap)
97 {
98 m_bitmap = bitmap;
99 }
100
101 private:
102 DecorationLayerTextureUpdater() { }
103 SkBitmap m_bitmap;
104 };
105
106 PassRefPtr<DecorationLayerChromium> DecorationLayerChromium::create()
107 {
108 return adoptRef(new DecorationLayerChromium());
109 }
110
111 DecorationLayerChromium::DecorationLayerChromium()
112 : LayerChromium()
113 {
114 }
115
116 DecorationLayerChromium::~DecorationLayerChromium()
117 {
118 }
119
120 PassOwnPtr<CCLayerImpl> DecorationLayerChromium::createCCLayerImpl()
121 {
122 return CCDecorationLayerImpl::create(id());
123 }
124
125 void DecorationLayerChromium::setTexturePriorities(const CCPriorityCalculator& p riorityCalc)
126 {
127 if (!m_bitmap.isNull() && !m_texture.get()) {
128 createTextureUpdaterIfNeeded();
129 m_textureUpdater->setBitmap(m_bitmap);
130 m_needsDisplay = false;
131 m_texture = m_textureUpdater->createTexture(layerTreeHost()->contentsTex tureManager());
132 }
133 }
134
135 void DecorationLayerChromium::setBitmap(const SkBitmap& bitmap, const IntRect& a perture) {
136 m_bitmap = bitmap;
137 m_imageAperture = aperture;
138 setNeedsDisplay();
139 }
140
141 void DecorationLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclus ionTracker* occlusion, CCRenderingStats& stats)
142 {
143 createTextureUpdaterIfNeeded();
144
145 IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bitmap .height()));
146
147 ASSERT(m_texture.get());
148 TextureUploader::Parameters upload = { m_texture.get(), contentRect, IntSize () };
149 queue.appendFullUpload(upload);
150 }
151
152 void DecorationLayerChromium::createTextureUpdaterIfNeeded()
153 {
154 if (m_textureUpdater)
155 return;
156
157 m_textureUpdater = DecorationLayerTextureUpdater::create();
158 }
159
160 bool DecorationLayerChromium::drawsContent() const
161 {
162 bool draws = !m_bitmap.isNull() && LayerChromium::drawsContent();
163 return draws;
164 }
165
166 bool DecorationLayerChromium::needsContentsScale() const
167 {
168 return false;
169 }
170
171 void DecorationLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
172 {
173 LayerChromium::pushPropertiesTo(layer);
174 CCDecorationLayerImpl* layerImpl = static_cast<CCDecorationLayerImpl*>(layer );
175
176 layerImpl->setResourceId(m_texture->texture()->resourceId());
177 layerImpl->setDecorationLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
178 }
179
180 }
181 #endif // USE(ACCELERATED_COMPOSITING)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698