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

Side by Side Diff: cc/resource_provider_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698