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

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: hacky rebase for Jerome to use Created 8 years, 2 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
« no previous file with comments | « cc/DecorationLayerChromium.h ('k') | cc/DecorationLayerChromiumTest.cpp » ('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 "DecorationLayerChromium.h"
8
9 #include "CCLayerTreeHost.h"
10 #include "CCDecorationLayerImpl.h"
11 #include "CCTextureUpdateQueue.h"
12 #include "LayerTextureUpdater.h"
13 #include "PlatformColor.h"
14 #include "TextureUploader.h"
15
16 namespace cc {
17
18 class DecorationLayerTextureUpdater : public LayerTextureUpdater {
19 public:
20 class Texture : public LayerTextureUpdater::Texture {
21 public:
22 Texture(DecorationLayerTextureUpdater* textureUpdater, scoped_ptr<CCPrio ritizedTexture> texture)
23 : LayerTextureUpdater::Texture(texture.Pass())
24 , m_textureUpdater(textureUpdater)
25 {
26 }
27
28 virtual void update(CCTextureUpdateQueue& queue, const IntRect& sourceRe ct, const IntSize& destOffset, bool partialUpdate, CCRenderingStats&) OVERRIDE
29 {
30 }
31
32 private:
33 DecorationLayerTextureUpdater* textureUpdater() { return m_textureUpdate r; }
34
35 DecorationLayerTextureUpdater* m_textureUpdater;
36 };
37
38 static PassRefPtr<DecorationLayerTextureUpdater> create()
39 {
40 return adoptRef(new DecorationLayerTextureUpdater());
41 }
42
43 virtual ~DecorationLayerTextureUpdater() { }
44
45 virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(CCPrioritized TextureManager* manager)
46 {
47 ASSERT(!m_bitmap.isNull());
48
49 scoped_ptr<CCPrioritizedTexture> texture = CCPrioritizedTexture::create( manager);
50 return adoptPtr(new Texture(this, texture.Pass()));
51 }
52
53 virtual SampledTexelFormat sampledTexelFormat(GC3Denum textureFormat) OVERRI DE
54 {
55 return PlatformColor::sameComponentOrder(textureFormat) ?
56 LayerTextureUpdater::SampledTexelFormatRGBA : LayerTextureUpdate r::SampledTexelFormatBGRA;
57 }
58
59 void setBitmap(const SkBitmap& bitmap)
60 {
61 m_bitmap = bitmap;
62 }
63
64 private:
65 DecorationLayerTextureUpdater() { }
66 SkBitmap m_bitmap;
67 };
68
69 scoped_refptr<DecorationLayerChromium> DecorationLayerChromium::create()
70 {
71 return make_scoped_refptr(new DecorationLayerChromium());
72 }
73
74 DecorationLayerChromium::DecorationLayerChromium()
75 : LayerChromium()
76 , m_bitmapDirty(false)
77 {
78 }
79
80 DecorationLayerChromium::~DecorationLayerChromium()
81 {
82 }
83
84 scoped_ptr<CCLayerImpl> DecorationLayerChromium::createCCLayerImpl()
85 {
86 return CCDecorationLayerImpl::create(id()).PassAs<CCLayerImpl>();
87 }
88
89 void DecorationLayerChromium::setTexturePriorities(const CCPriorityCalculator& p riorityCalc)
90 {
91 if (m_needsDisplay && m_bitmapDirty && drawsContent()) {
92 ASSERT(!m_bitmap.isNull());
93 createTextureUpdaterIfNeeded();
94 m_textureUpdater->setBitmap(m_bitmap);
95 m_needsDisplay = false;
96
97 if (!m_texture.get())
98 m_texture = m_textureUpdater->createTexture(layerTreeHost()->content sTextureManager());
99 }
100
101 if (m_texture.get()) {
102 m_texture->texture()->setRequestPriority(CCPriorityCalculator::uiPriorit y(true));
103 // FIXME: Need to support swizzle in the shader for !PlatformColor::same ComponentOrder(textureFormat)
104 GC3Denum textureFormat = layerTreeHost()->rendererCapabilities().bestTex tureFormat;
105 m_texture->texture()->setDimensions(IntSize(m_bitmap.width(), m_bitmap.h eight()), textureFormat);
106 }
107 }
108
109 void DecorationLayerChromium::setBitmap(const SkBitmap& bitmap, const IntRect& a perture) {
110 m_bitmap = bitmap;
111 m_imageAperture = aperture;
112 m_bitmapDirty = true;
113 setNeedsDisplay();
114 }
115
116 void DecorationLayerChromium::update(CCTextureUpdateQueue& queue, const CCOcclus ionTracker* occlusion, CCRenderingStats& stats)
117 {
118 createTextureUpdaterIfNeeded();
119
120 // FIXME: Or should this query backingResourceWasEvicted()?
121 if (m_texture.get() && (m_bitmapDirty || !m_texture->texture()->haveBackingT exture())) {
122 IntRect contentRect = IntRect(IntPoint(), IntSize(m_bitmap.width(), m_bi tmap.height()));
123 TextureUploader::Parameters upload = { m_texture->texture(), &m_bitmap, NULL, { contentRect, contentRect, IntSize() } };
124 queue.appendFullUpload(upload);
125 m_bitmapDirty = false;
126 }
127 }
128
129 void DecorationLayerChromium::createTextureUpdaterIfNeeded()
130 {
131 if (m_textureUpdater)
132 return;
133
134 m_textureUpdater = DecorationLayerTextureUpdater::create();
135 }
136
137 bool DecorationLayerChromium::drawsContent() const
138 {
139 bool draws = !m_bitmap.isNull() && LayerChromium::drawsContent() && m_bitmap .width() && m_bitmap.height();
140 return draws;
141 }
142
143 bool DecorationLayerChromium::needsContentsScale() const
144 {
145 return false;
146 }
147
148 void DecorationLayerChromium::pushPropertiesTo(CCLayerImpl* layer)
149 {
150 LayerChromium::pushPropertiesTo(layer);
151 CCDecorationLayerImpl* layerImpl = static_cast<CCDecorationLayerImpl*>(layer );
152
153 if (m_texture.get())
154 layerImpl->setResourceId(m_texture->texture()->resourceId());
155 layerImpl->setDecorationLayout(IntSize(m_bitmap.width(), m_bitmap.height()), m_imageAperture);
156 }
157
158 }
OLDNEW
« no previous file with comments | « cc/DecorationLayerChromium.h ('k') | cc/DecorationLayerChromiumTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698