| OLD | NEW |
| 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 "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 base::hash_map<unsigned, uint32> sync_point_for_mailbox_; | 163 base::hash_map<unsigned, uint32> sync_point_for_mailbox_; |
| 164 }; | 164 }; |
| 165 | 165 |
| 166 class ResourceProviderContext : public TestWebGraphicsContext3D { | 166 class ResourceProviderContext : public TestWebGraphicsContext3D { |
| 167 public: | 167 public: |
| 168 static scoped_ptr<ResourceProviderContext> Create( | 168 static scoped_ptr<ResourceProviderContext> Create( |
| 169 ContextSharedData* shared_data) { | 169 ContextSharedData* shared_data) { |
| 170 return make_scoped_ptr(new ResourceProviderContext(shared_data)); | 170 return make_scoped_ptr(new ResourceProviderContext(shared_data)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 virtual GLuint insertSyncPoint() override { | 173 GLuint insertSyncPoint() override { |
| 174 uint32 sync_point = shared_data_->InsertSyncPoint(); | 174 uint32 sync_point = shared_data_->InsertSyncPoint(); |
| 175 // Commit the produceTextureCHROMIUM calls at this point, so that | 175 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 176 // they're associated with the sync point. | 176 // they're associated with the sync point. |
| 177 for (PendingProduceTextureList::iterator it = | 177 for (PendingProduceTextureList::iterator it = |
| 178 pending_produce_textures_.begin(); | 178 pending_produce_textures_.begin(); |
| 179 it != pending_produce_textures_.end(); | 179 it != pending_produce_textures_.end(); |
| 180 ++it) { | 180 ++it) { |
| 181 shared_data_->ProduceTexture( | 181 shared_data_->ProduceTexture( |
| 182 (*it)->mailbox, sync_point, (*it)->texture); | 182 (*it)->mailbox, sync_point, (*it)->texture); |
| 183 } | 183 } |
| 184 pending_produce_textures_.clear(); | 184 pending_produce_textures_.clear(); |
| 185 return sync_point; | 185 return sync_point; |
| 186 } | 186 } |
| 187 | 187 |
| 188 virtual void waitSyncPoint(GLuint sync_point) override { | 188 void waitSyncPoint(GLuint sync_point) override { |
| 189 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 189 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
| 190 } | 190 } |
| 191 | 191 |
| 192 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } | 192 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } |
| 193 | 193 |
| 194 virtual void texStorage2DEXT(GLenum target, | 194 void texStorage2DEXT(GLenum target, |
| 195 GLint levels, | 195 GLint levels, |
| 196 GLuint internalformat, | 196 GLuint internalformat, |
| 197 GLint width, | 197 GLint width, |
| 198 GLint height) override { | 198 GLint height) override { |
| 199 CheckTextureIsBound(target); | 199 CheckTextureIsBound(target); |
| 200 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 200 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 201 ASSERT_EQ(1, levels); | 201 ASSERT_EQ(1, levels); |
| 202 GLenum format = GL_RGBA; | 202 GLenum format = GL_RGBA; |
| 203 switch (internalformat) { | 203 switch (internalformat) { |
| 204 case GL_RGBA8_OES: | 204 case GL_RGBA8_OES: |
| 205 break; | 205 break; |
| 206 case GL_BGRA8_EXT: | 206 case GL_BGRA8_EXT: |
| 207 format = GL_BGRA_EXT; | 207 format = GL_BGRA_EXT; |
| 208 break; | 208 break; |
| 209 default: | 209 default: |
| 210 NOTREACHED(); | 210 NOTREACHED(); |
| 211 } | 211 } |
| 212 AllocateTexture(gfx::Size(width, height), format); | 212 AllocateTexture(gfx::Size(width, height), format); |
| 213 } | 213 } |
| 214 | 214 |
| 215 virtual void texImage2D(GLenum target, | 215 void texImage2D(GLenum target, |
| 216 GLint level, | 216 GLint level, |
| 217 GLenum internalformat, | 217 GLenum internalformat, |
| 218 GLsizei width, | 218 GLsizei width, |
| 219 GLsizei height, | 219 GLsizei height, |
| 220 GLint border, | 220 GLint border, |
| 221 GLenum format, | 221 GLenum format, |
| 222 GLenum type, | 222 GLenum type, |
| 223 const void* pixels) override { | 223 const void* pixels) override { |
| 224 CheckTextureIsBound(target); | 224 CheckTextureIsBound(target); |
| 225 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 225 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 226 ASSERT_FALSE(level); | 226 ASSERT_FALSE(level); |
| 227 ASSERT_EQ(internalformat, format); | 227 ASSERT_EQ(internalformat, format); |
| 228 ASSERT_FALSE(border); | 228 ASSERT_FALSE(border); |
| 229 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 229 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 230 AllocateTexture(gfx::Size(width, height), format); | 230 AllocateTexture(gfx::Size(width, height), format); |
| 231 if (pixels) | 231 if (pixels) |
| 232 SetPixels(0, 0, width, height, pixels); | 232 SetPixels(0, 0, width, height, pixels); |
| 233 } | 233 } |
| 234 | 234 |
| 235 virtual void texSubImage2D(GLenum target, | 235 void texSubImage2D(GLenum target, |
| 236 GLint level, | 236 GLint level, |
| 237 GLint xoffset, | 237 GLint xoffset, |
| 238 GLint yoffset, | 238 GLint yoffset, |
| 239 GLsizei width, | 239 GLsizei width, |
| 240 GLsizei height, | 240 GLsizei height, |
| 241 GLenum format, | 241 GLenum format, |
| 242 GLenum type, | 242 GLenum type, |
| 243 const void* pixels) override { | 243 const void* pixels) override { |
| 244 CheckTextureIsBound(target); | 244 CheckTextureIsBound(target); |
| 245 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 245 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 246 ASSERT_FALSE(level); | 246 ASSERT_FALSE(level); |
| 247 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 247 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 248 { | 248 { |
| 249 base::AutoLock lock_for_texture_access(namespace_->lock); | 249 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 250 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); | 250 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); |
| 251 } | 251 } |
| 252 ASSERT_TRUE(pixels); | 252 ASSERT_TRUE(pixels); |
| 253 SetPixels(xoffset, yoffset, width, height, pixels); | 253 SetPixels(xoffset, yoffset, width, height, pixels); |
| 254 } | 254 } |
| 255 | 255 |
| 256 virtual void genMailboxCHROMIUM(GLbyte* mailbox) override { | 256 void genMailboxCHROMIUM(GLbyte* mailbox) override { |
| 257 return shared_data_->GenMailbox(mailbox); | 257 return shared_data_->GenMailbox(mailbox); |
| 258 } | 258 } |
| 259 | 259 |
| 260 virtual void produceTextureCHROMIUM(GLenum target, | 260 void produceTextureCHROMIUM(GLenum target, const GLbyte* mailbox) override { |
| 261 const GLbyte* mailbox) override { | |
| 262 CheckTextureIsBound(target); | 261 CheckTextureIsBound(target); |
| 263 | 262 |
| 264 // Delay moving the texture into the mailbox until the next | 263 // Delay moving the texture into the mailbox until the next |
| 265 // InsertSyncPoint, so that it is not visible to other contexts that | 264 // InsertSyncPoint, so that it is not visible to other contexts that |
| 266 // haven't waited on that sync point. | 265 // haven't waited on that sync point. |
| 267 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 266 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
| 268 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 267 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
| 269 base::AutoLock lock_for_texture_access(namespace_->lock); | 268 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 270 pending->texture = BoundTexture(target); | 269 pending->texture = BoundTexture(target); |
| 271 pending_produce_textures_.push_back(pending.Pass()); | 270 pending_produce_textures_.push_back(pending.Pass()); |
| 272 } | 271 } |
| 273 | 272 |
| 274 virtual void consumeTextureCHROMIUM(GLenum target, | 273 void consumeTextureCHROMIUM(GLenum target, const GLbyte* mailbox) override { |
| 275 const GLbyte* mailbox) override { | |
| 276 CheckTextureIsBound(target); | 274 CheckTextureIsBound(target); |
| 277 base::AutoLock lock_for_texture_access(namespace_->lock); | 275 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 278 scoped_refptr<TestTexture> texture = | 276 scoped_refptr<TestTexture> texture = |
| 279 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); | 277 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); |
| 280 namespace_->textures.Replace(BoundTextureId(target), texture); | 278 namespace_->textures.Replace(BoundTextureId(target), texture); |
| 281 } | 279 } |
| 282 | 280 |
| 283 void GetPixels(const gfx::Size& size, | 281 void GetPixels(const gfx::Size& size, |
| 284 ResourceFormat format, | 282 ResourceFormat format, |
| 285 uint8_t* pixels) { | 283 uint8_t* pixels) { |
| (...skipping 3311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3597 resource_provider->DeleteResource(id); | 3595 resource_provider->DeleteResource(id); |
| 3598 } | 3596 } |
| 3599 | 3597 |
| 3600 INSTANTIATE_TEST_CASE_P( | 3598 INSTANTIATE_TEST_CASE_P( |
| 3601 ResourceProviderTests, | 3599 ResourceProviderTests, |
| 3602 ResourceProviderTest, | 3600 ResourceProviderTest, |
| 3603 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 3601 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 3604 | 3602 |
| 3605 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { | 3603 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { |
| 3606 public: | 3604 public: |
| 3607 virtual GLuint NextTextureId() override { | 3605 GLuint NextTextureId() override { |
| 3608 base::AutoLock lock(namespace_->lock); | 3606 base::AutoLock lock(namespace_->lock); |
| 3609 return namespace_->next_texture_id++; | 3607 return namespace_->next_texture_id++; |
| 3610 } | 3608 } |
| 3611 virtual void RetireTextureId(GLuint) override {} | 3609 void RetireTextureId(GLuint) override {} |
| 3612 GLuint PeekTextureId() { | 3610 GLuint PeekTextureId() { |
| 3613 base::AutoLock lock(namespace_->lock); | 3611 base::AutoLock lock(namespace_->lock); |
| 3614 return namespace_->next_texture_id; | 3612 return namespace_->next_texture_id; |
| 3615 } | 3613 } |
| 3616 }; | 3614 }; |
| 3617 | 3615 |
| 3618 TEST(ResourceProviderTest, TextureAllocationChunkSize) { | 3616 TEST(ResourceProviderTest, TextureAllocationChunkSize) { |
| 3619 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( | 3617 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( |
| 3620 new TextureIdAllocationTrackingContext); | 3618 new TextureIdAllocationTrackingContext); |
| 3621 TextureIdAllocationTrackingContext* context = context_owned.get(); | 3619 TextureIdAllocationTrackingContext* context = context_owned.get(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3668 resource_provider->AllocateForTesting(id); | 3666 resource_provider->AllocateForTesting(id); |
| 3669 Mock::VerifyAndClearExpectations(context); | 3667 Mock::VerifyAndClearExpectations(context); |
| 3670 | 3668 |
| 3671 DCHECK_EQ(10u, context->PeekTextureId()); | 3669 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3672 resource_provider->DeleteResource(id); | 3670 resource_provider->DeleteResource(id); |
| 3673 } | 3671 } |
| 3674 } | 3672 } |
| 3675 | 3673 |
| 3676 } // namespace | 3674 } // namespace |
| 3677 } // namespace cc | 3675 } // namespace cc |
| OLD | NEW |