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

Side by Side Diff: cc/resource_provider_unittest.cc

Issue 11192030: cc: Switch to Chromium DCHECKs LOGs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebaseonenne 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/resource_provider.cc ('k') | cc/scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 6
7 #include "CCResourceProvider.h" 7 #include "CCResourceProvider.h"
8 8
9 #include "CCGraphicsContext.h" 9 #include "CCGraphicsContext.h"
10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread 10 #include "CCSingleThreadProxy.h" // For DebugScopedSetImplThread
11 #include "Extensions3DChromium.h" 11 #include "Extensions3DChromium.h"
12 #include "base/logging.h"
12 #include "cc/scoped_ptr_deque.h" 13 #include "cc/scoped_ptr_deque.h"
13 #include "cc/scoped_ptr_hash_map.h" 14 #include "cc/scoped_ptr_hash_map.h"
14 #include "cc/test/compositor_fake_web_graphics_context_3d.h" 15 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
15 #include "cc/test/fake_web_compositor_output_surface.h" 16 #include "cc/test/fake_web_compositor_output_surface.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include <public/WebGraphicsContext3D.h> 18 #include <public/WebGraphicsContext3D.h>
18 19
19 using namespace cc; 20 using namespace cc;
20 using namespace WebKit; 21 using namespace WebKit;
21 22
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 { 54 {
54 memset(mailbox, 0, sizeof(WGC3Dbyte[64])); 55 memset(mailbox, 0, sizeof(WGC3Dbyte[64]));
55 memcpy(mailbox, &m_nextMailBox, sizeof(m_nextMailBox)); 56 memcpy(mailbox, &m_nextMailBox, sizeof(m_nextMailBox));
56 ++m_nextMailBox; 57 ++m_nextMailBox;
57 } 58 }
58 59
59 void produceTexture(const WGC3Dbyte* mailboxName, unsigned syncPoint, scoped _ptr<Texture> texture) 60 void produceTexture(const WGC3Dbyte* mailboxName, unsigned syncPoint, scoped _ptr<Texture> texture)
60 { 61 {
61 unsigned mailbox = 0; 62 unsigned mailbox = 0;
62 memcpy(&mailbox, mailboxName, sizeof(mailbox)); 63 memcpy(&mailbox, mailboxName, sizeof(mailbox));
63 ASSERT(mailbox && mailbox < m_nextMailBox); 64 ASSERT_TRUE(mailbox && mailbox < m_nextMailBox);
64 m_textures.set(mailbox, texture.Pass()); 65 m_textures.set(mailbox, texture.Pass());
65 ASSERT(m_syncPointForMailbox[mailbox] < syncPoint); 66 ASSERT_LT(m_syncPointForMailbox[mailbox], syncPoint);
66 m_syncPointForMailbox[mailbox] = syncPoint; 67 m_syncPointForMailbox[mailbox] = syncPoint;
67 } 68 }
68 69
69 scoped_ptr<Texture> consumeTexture(const WGC3Dbyte* mailboxName, unsigned sy ncPoint) 70 scoped_ptr<Texture> consumeTexture(const WGC3Dbyte* mailboxName, unsigned sy ncPoint)
70 { 71 {
71 unsigned mailbox = 0; 72 unsigned mailbox = 0;
72 memcpy(&mailbox, mailboxName, sizeof(mailbox)); 73 memcpy(&mailbox, mailboxName, sizeof(mailbox));
73 ASSERT(mailbox && mailbox < m_nextMailBox); 74 DCHECK(mailbox && mailbox < m_nextMailBox);
74 75
75 // If the latest sync point the context has waited on is before the sync 76 // If the latest sync point the context has waited on is before the sync
76 // point for when the mailbox was set, pretend we never saw that 77 // point for when the mailbox was set, pretend we never saw that
77 // produceTexture. 78 // produceTexture.
78 if (m_syncPointForMailbox[mailbox] < syncPoint) 79 if (m_syncPointForMailbox[mailbox] < syncPoint)
79 return scoped_ptr<Texture>(); 80 return scoped_ptr<Texture>();
80 return m_textures.take(mailbox); 81 return m_textures.take(mailbox);
81 } 82 }
82 83
83 private: 84 private:
(...skipping 24 matching lines...) Expand all
108 return syncPoint; 109 return syncPoint;
109 } 110 }
110 111
111 virtual void waitSyncPoint(unsigned syncPoint) 112 virtual void waitSyncPoint(unsigned syncPoint)
112 { 113 {
113 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint); 114 m_lastWaitedSyncPoint = std::max(syncPoint, m_lastWaitedSyncPoint);
114 } 115 }
115 116
116 virtual void bindTexture(WGC3Denum target, WebGLId texture) 117 virtual void bindTexture(WGC3Denum target, WebGLId texture)
117 { 118 {
118 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 119 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
119 ASSERT(!texture || m_textures.find(texture) != m_textures.end()); 120 ASSERT_TRUE(!texture || m_textures.find(texture) != m_textures.end());
120 m_currentTexture = texture; 121 m_currentTexture = texture;
121 } 122 }
122 123
123 virtual WebGLId createTexture() 124 virtual WebGLId createTexture()
124 { 125 {
125 WebGLId id = CompositorFakeWebGraphicsContext3D::createTexture(); 126 WebGLId id = CompositorFakeWebGraphicsContext3D::createTexture();
126 m_textures.add(id, scoped_ptr<Texture>()); 127 m_textures.add(id, scoped_ptr<Texture>());
127 return id; 128 return id;
128 } 129 }
129 130
130 virtual void deleteTexture(WebGLId id) 131 virtual void deleteTexture(WebGLId id)
131 { 132 {
132 TextureMap::iterator it = m_textures.find(id); 133 TextureMap::iterator it = m_textures.find(id);
133 ASSERT(it != m_textures.end()); 134 ASSERT_FALSE(it == m_textures.end());
134 m_textures.erase(it); 135 m_textures.erase(it);
135 if (m_currentTexture == id) 136 if (m_currentTexture == id)
136 m_currentTexture = 0; 137 m_currentTexture = 0;
137 } 138 }
138 139
139 virtual void texStorage2DEXT(WGC3Denum target, WGC3Dint levels, WGC3Duint in ternalformat, 140 virtual void texStorage2DEXT(WGC3Denum target, WGC3Dint levels, WGC3Duint in ternalformat,
140 WGC3Dint width, WGC3Dint height) 141 WGC3Dint width, WGC3Dint height)
141 { 142 {
142 ASSERT(m_currentTexture); 143 ASSERT_TRUE(m_currentTexture);
143 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 144 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
144 ASSERT(levels == 1); 145 ASSERT_EQ(levels, 1);
145 WGC3Denum format = GraphicsContext3D::RGBA; 146 WGC3Denum format = GraphicsContext3D::RGBA;
146 switch (internalformat) { 147 switch (internalformat) {
147 case Extensions3D::RGBA8_OES: 148 case Extensions3D::RGBA8_OES:
148 break; 149 break;
149 case Extensions3DChromium::BGRA8_EXT: 150 case Extensions3DChromium::BGRA8_EXT:
150 format = Extensions3D::BGRA_EXT; 151 format = Extensions3D::BGRA_EXT;
151 break; 152 break;
152 default: 153 default:
153 ASSERT_NOT_REACHED(); 154 NOTREACHED();
154 } 155 }
155 allocateTexture(IntSize(width, height), format); 156 allocateTexture(IntSize(width, height), format);
156 } 157 }
157 158
158 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels) 159 virtual void texImage2D(WGC3Denum target, WGC3Dint level, WGC3Denum internal format, WGC3Dsizei width, WGC3Dsizei height, WGC3Dint border, WGC3Denum format, WGC3Denum type, const void* pixels)
159 { 160 {
160 ASSERT(m_currentTexture); 161 ASSERT_TRUE(m_currentTexture);
161 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 162 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
162 ASSERT(!level); 163 ASSERT_FALSE(level);
163 ASSERT(internalformat == format); 164 ASSERT_EQ(internalformat, format);
164 ASSERT(!border); 165 ASSERT_FALSE(border);
165 ASSERT(type == GraphicsContext3D::UNSIGNED_BYTE); 166 ASSERT_EQ(type, GraphicsContext3D::UNSIGNED_BYTE);
166 allocateTexture(IntSize(width, height), format); 167 allocateTexture(IntSize(width, height), format);
167 if (pixels) 168 if (pixels)
168 setPixels(0, 0, width, height, pixels); 169 setPixels(0, 0, width, height, pixels);
169 } 170 }
170 171
171 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3 Denum type, const void* pixels) 172 virtual void texSubImage2D(WGC3Denum target, WGC3Dint level, WGC3Dint xoffse t, WGC3Dint yoffset, WGC3Dsizei width, WGC3Dsizei height, WGC3Denum format, WGC3 Denum type, const void* pixels)
172 { 173 {
173 ASSERT(m_currentTexture); 174 ASSERT_TRUE(m_currentTexture);
174 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 175 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
175 ASSERT(!level); 176 ASSERT_FALSE(level);
176 ASSERT(m_textures.get(m_currentTexture)); 177 ASSERT_TRUE(m_textures.get(m_currentTexture));
177 ASSERT(m_textures.get(m_currentTexture)->format == format); 178 ASSERT_EQ(m_textures.get(m_currentTexture)->format, format);
178 ASSERT(type == GraphicsContext3D::UNSIGNED_BYTE); 179 ASSERT_EQ(type, GraphicsContext3D::UNSIGNED_BYTE);
179 ASSERT(pixels); 180 ASSERT_TRUE(pixels);
180 setPixels(xoffset, yoffset, width, height, pixels); 181 setPixels(xoffset, yoffset, width, height, pixels);
181 } 182 }
182 183
183 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) { return m_sharedData->g enMailbox(mailbox); } 184 virtual void genMailboxCHROMIUM(WGC3Dbyte* mailbox) { return m_sharedData->g enMailbox(mailbox); }
184 virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb ox) 185 virtual void produceTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb ox)
185 { 186 {
186 ASSERT(m_currentTexture); 187 ASSERT_TRUE(m_currentTexture);
187 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 188 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
188 189
189 // Delay moving the texture into the mailbox until the next 190 // Delay moving the texture into the mailbox until the next
190 // insertSyncPoint, so that it is not visible to other contexts that 191 // insertSyncPoint, so that it is not visible to other contexts that
191 // haven't waited on that sync point. 192 // haven't waited on that sync point.
192 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); 193 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture);
193 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); 194 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox));
194 pending->texture = m_textures.take(m_currentTexture); 195 pending->texture = m_textures.take(m_currentTexture);
195 m_textures.set(m_currentTexture, scoped_ptr<Texture>()); 196 m_textures.set(m_currentTexture, scoped_ptr<Texture>());
196 m_pendingProduceTextures.append(pending.Pass()); 197 m_pendingProduceTextures.append(pending.Pass());
197 } 198 }
198 199
199 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb ox) 200 virtual void consumeTextureCHROMIUM(WGC3Denum target, const WGC3Dbyte* mailb ox)
200 { 201 {
201 ASSERT(m_currentTexture); 202 ASSERT_TRUE(m_currentTexture);
202 ASSERT(target == GraphicsContext3D::TEXTURE_2D); 203 ASSERT_EQ(target, GraphicsContext3D::TEXTURE_2D);
203 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m _lastWaitedSyncPoint)); 204 m_textures.set(m_currentTexture, m_sharedData->consumeTexture(mailbox, m _lastWaitedSyncPoint));
204 } 205 }
205 206
206 void getPixels(const IntSize& size, WGC3Denum format, uint8_t* pixels) 207 void getPixels(const IntSize& size, WGC3Denum format, uint8_t* pixels)
207 { 208 {
208 ASSERT(m_currentTexture); 209 ASSERT_TRUE(m_currentTexture);
209 Texture* texture = m_textures.get(m_currentTexture); 210 Texture* texture = m_textures.get(m_currentTexture);
210 ASSERT(texture); 211 ASSERT_TRUE(texture);
211 ASSERT(texture->size == size); 212 ASSERT_EQ(texture->size, size);
212 ASSERT(texture->format == format); 213 ASSERT_EQ(texture->format, format);
213 memcpy(pixels, texture->data.get(), textureSize(size, format)); 214 memcpy(pixels, texture->data.get(), textureSize(size, format));
214 } 215 }
215 216
216 int textureCount() 217 int textureCount()
217 { 218 {
218 return m_textures.size(); 219 return m_textures.size();
219 } 220 }
220 221
221 protected: 222 protected:
222 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa ta) 223 ResourceProviderContext(const Attributes& attrs, ContextSharedData* sharedDa ta)
223 : CompositorFakeWebGraphicsContext3D(attrs) 224 : CompositorFakeWebGraphicsContext3D(attrs)
224 , m_sharedData(sharedData) 225 , m_sharedData(sharedData)
225 , m_currentTexture(0) 226 , m_currentTexture(0)
226 , m_lastWaitedSyncPoint(0) 227 , m_lastWaitedSyncPoint(0)
227 { } 228 { }
228 229
229 private: 230 private:
230 void allocateTexture(const IntSize& size, WGC3Denum format) 231 void allocateTexture(const IntSize& size, WGC3Denum format)
231 { 232 {
232 ASSERT(m_currentTexture); 233 ASSERT_TRUE(m_currentTexture);
233 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma t))); 234 m_textures.set(m_currentTexture, make_scoped_ptr(new Texture(size, forma t)));
234 } 235 }
235 236
236 void setPixels(int xoffset, int yoffset, int width, int height, const void* pixels) 237 void setPixels(int xoffset, int yoffset, int width, int height, const void* pixels)
237 { 238 {
238 ASSERT(m_currentTexture); 239 ASSERT_TRUE(m_currentTexture);
239 Texture* texture = m_textures.get(m_currentTexture); 240 Texture* texture = m_textures.get(m_currentTexture);
240 ASSERT(texture); 241 ASSERT_TRUE(texture);
241 ASSERT(xoffset >= 0 && xoffset+width <= texture->size.width()); 242 ASSERT_TRUE(xoffset >= 0 && xoffset+width <= texture->size.width());
242 ASSERT(yoffset >= 0 && yoffset+height <= texture->size.height()); 243 ASSERT_TRUE(yoffset >= 0 && yoffset+height <= texture->size.height());
243 ASSERT(pixels); 244 ASSERT_TRUE(pixels);
244 size_t inPitch = textureSize(IntSize(width, 1), texture->format); 245 size_t inPitch = textureSize(IntSize(width, 1), texture->format);
245 size_t outPitch = textureSize(IntSize(texture->size.width(), 1), texture ->format); 246 size_t outPitch = textureSize(IntSize(texture->size.width(), 1), texture ->format);
246 uint8_t* dest = texture->data.get() + yoffset * outPitch + textureSize(I ntSize(xoffset, 1), texture->format); 247 uint8_t* dest = texture->data.get() + yoffset * outPitch + textureSize(I ntSize(xoffset, 1), texture->format);
247 const uint8_t* src = static_cast<const uint8_t*>(pixels); 248 const uint8_t* src = static_cast<const uint8_t*>(pixels);
248 for (int i = 0; i < height; ++i) { 249 for (int i = 0; i < height; ++i) {
249 memcpy(dest, src, inPitch); 250 memcpy(dest, src, inPitch);
250 dest += outPitch; 251 dest += outPitch;
251 src += inPitch; 252 src += inPitch;
252 } 253 }
253 } 254 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 579 }
579 EXPECT_EQ(0u, childResourceProvider->numResources()); 580 EXPECT_EQ(0u, childResourceProvider->numResources());
580 } 581 }
581 582
582 INSTANTIATE_TEST_CASE_P(CCResourceProviderTests, 583 INSTANTIATE_TEST_CASE_P(CCResourceProviderTests,
583 CCResourceProviderTest, 584 CCResourceProviderTest,
584 ::testing::Values(CCResourceProvider::GLTexture, 585 ::testing::Values(CCResourceProvider::GLTexture,
585 CCResourceProvider::Bitmap)); 586 CCResourceProvider::Bitmap));
586 587
587 } // namespace 588 } // namespace
OLDNEW
« no previous file with comments | « cc/resource_provider.cc ('k') | cc/scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698