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

Side by Side Diff: cc/resource_provider_unittest.cc

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