| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); | 94 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); |
| 95 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); | 95 MOCK_METHOD1(waitSyncPoint, void(GLuint sync_point)); |
| 96 MOCK_METHOD0(insertSyncPoint, GLuint(void)); | 96 MOCK_METHOD0(insertSyncPoint, GLuint(void)); |
| 97 MOCK_METHOD2(produceTextureCHROMIUM, | 97 MOCK_METHOD2(produceTextureCHROMIUM, |
| 98 void(GLenum target, const GLbyte* mailbox)); | 98 void(GLenum target, const GLbyte* mailbox)); |
| 99 MOCK_METHOD2(consumeTextureCHROMIUM, | 99 MOCK_METHOD2(consumeTextureCHROMIUM, |
| 100 void(GLenum target, const GLbyte* mailbox)); | 100 void(GLenum target, const GLbyte* mailbox)); |
| 101 | 101 |
| 102 // Force all textures to be consecutive numbers starting at "1", | 102 // Force all textures to be consecutive numbers starting at "1", |
| 103 // so we easily can test for them. | 103 // so we easily can test for them. |
| 104 virtual GLuint NextTextureId() OVERRIDE { | 104 virtual GLuint NextTextureId() override { |
| 105 base::AutoLock lock(namespace_->lock); | 105 base::AutoLock lock(namespace_->lock); |
| 106 return namespace_->next_texture_id++; | 106 return namespace_->next_texture_id++; |
| 107 } | 107 } |
| 108 virtual void RetireTextureId(GLuint) OVERRIDE {} | 108 virtual void RetireTextureId(GLuint) override {} |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // Shared data between multiple ResourceProviderContext. This contains mailbox | 111 // Shared data between multiple ResourceProviderContext. This contains mailbox |
| 112 // contents as well as information about sync points. | 112 // contents as well as information about sync points. |
| 113 class ContextSharedData { | 113 class ContextSharedData { |
| 114 public: | 114 public: |
| 115 static scoped_ptr<ContextSharedData> Create() { | 115 static scoped_ptr<ContextSharedData> Create() { |
| 116 return make_scoped_ptr(new ContextSharedData()); | 116 return make_scoped_ptr(new ContextSharedData()); |
| 117 } | 117 } |
| 118 | 118 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 base::hash_map<unsigned, uint32> sync_point_for_mailbox_; | 161 base::hash_map<unsigned, uint32> sync_point_for_mailbox_; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 class ResourceProviderContext : public TestWebGraphicsContext3D { | 164 class ResourceProviderContext : public TestWebGraphicsContext3D { |
| 165 public: | 165 public: |
| 166 static scoped_ptr<ResourceProviderContext> Create( | 166 static scoped_ptr<ResourceProviderContext> Create( |
| 167 ContextSharedData* shared_data) { | 167 ContextSharedData* shared_data) { |
| 168 return make_scoped_ptr(new ResourceProviderContext(shared_data)); | 168 return make_scoped_ptr(new ResourceProviderContext(shared_data)); |
| 169 } | 169 } |
| 170 | 170 |
| 171 virtual GLuint insertSyncPoint() OVERRIDE { | 171 virtual GLuint insertSyncPoint() override { |
| 172 uint32 sync_point = shared_data_->InsertSyncPoint(); | 172 uint32 sync_point = shared_data_->InsertSyncPoint(); |
| 173 // Commit the produceTextureCHROMIUM calls at this point, so that | 173 // Commit the produceTextureCHROMIUM calls at this point, so that |
| 174 // they're associated with the sync point. | 174 // they're associated with the sync point. |
| 175 for (PendingProduceTextureList::iterator it = | 175 for (PendingProduceTextureList::iterator it = |
| 176 pending_produce_textures_.begin(); | 176 pending_produce_textures_.begin(); |
| 177 it != pending_produce_textures_.end(); | 177 it != pending_produce_textures_.end(); |
| 178 ++it) { | 178 ++it) { |
| 179 shared_data_->ProduceTexture( | 179 shared_data_->ProduceTexture( |
| 180 (*it)->mailbox, sync_point, (*it)->texture); | 180 (*it)->mailbox, sync_point, (*it)->texture); |
| 181 } | 181 } |
| 182 pending_produce_textures_.clear(); | 182 pending_produce_textures_.clear(); |
| 183 return sync_point; | 183 return sync_point; |
| 184 } | 184 } |
| 185 | 185 |
| 186 virtual void waitSyncPoint(GLuint sync_point) OVERRIDE { | 186 virtual void waitSyncPoint(GLuint sync_point) override { |
| 187 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); | 187 last_waited_sync_point_ = std::max(sync_point, last_waited_sync_point_); |
| 188 } | 188 } |
| 189 | 189 |
| 190 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } | 190 unsigned last_waited_sync_point() const { return last_waited_sync_point_; } |
| 191 | 191 |
| 192 virtual void texStorage2DEXT(GLenum target, | 192 virtual void texStorage2DEXT(GLenum target, |
| 193 GLint levels, | 193 GLint levels, |
| 194 GLuint internalformat, | 194 GLuint internalformat, |
| 195 GLint width, | 195 GLint width, |
| 196 GLint height) OVERRIDE { | 196 GLint height) override { |
| 197 CheckTextureIsBound(target); | 197 CheckTextureIsBound(target); |
| 198 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 198 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 199 ASSERT_EQ(1, levels); | 199 ASSERT_EQ(1, levels); |
| 200 GLenum format = GL_RGBA; | 200 GLenum format = GL_RGBA; |
| 201 switch (internalformat) { | 201 switch (internalformat) { |
| 202 case GL_RGBA8_OES: | 202 case GL_RGBA8_OES: |
| 203 break; | 203 break; |
| 204 case GL_BGRA8_EXT: | 204 case GL_BGRA8_EXT: |
| 205 format = GL_BGRA_EXT; | 205 format = GL_BGRA_EXT; |
| 206 break; | 206 break; |
| 207 default: | 207 default: |
| 208 NOTREACHED(); | 208 NOTREACHED(); |
| 209 } | 209 } |
| 210 AllocateTexture(gfx::Size(width, height), format); | 210 AllocateTexture(gfx::Size(width, height), format); |
| 211 } | 211 } |
| 212 | 212 |
| 213 virtual void texImage2D(GLenum target, | 213 virtual void texImage2D(GLenum target, |
| 214 GLint level, | 214 GLint level, |
| 215 GLenum internalformat, | 215 GLenum internalformat, |
| 216 GLsizei width, | 216 GLsizei width, |
| 217 GLsizei height, | 217 GLsizei height, |
| 218 GLint border, | 218 GLint border, |
| 219 GLenum format, | 219 GLenum format, |
| 220 GLenum type, | 220 GLenum type, |
| 221 const void* pixels) OVERRIDE { | 221 const void* pixels) override { |
| 222 CheckTextureIsBound(target); | 222 CheckTextureIsBound(target); |
| 223 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 223 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 224 ASSERT_FALSE(level); | 224 ASSERT_FALSE(level); |
| 225 ASSERT_EQ(internalformat, format); | 225 ASSERT_EQ(internalformat, format); |
| 226 ASSERT_FALSE(border); | 226 ASSERT_FALSE(border); |
| 227 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 227 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 228 AllocateTexture(gfx::Size(width, height), format); | 228 AllocateTexture(gfx::Size(width, height), format); |
| 229 if (pixels) | 229 if (pixels) |
| 230 SetPixels(0, 0, width, height, pixels); | 230 SetPixels(0, 0, width, height, pixels); |
| 231 } | 231 } |
| 232 | 232 |
| 233 virtual void texSubImage2D(GLenum target, | 233 virtual void texSubImage2D(GLenum target, |
| 234 GLint level, | 234 GLint level, |
| 235 GLint xoffset, | 235 GLint xoffset, |
| 236 GLint yoffset, | 236 GLint yoffset, |
| 237 GLsizei width, | 237 GLsizei width, |
| 238 GLsizei height, | 238 GLsizei height, |
| 239 GLenum format, | 239 GLenum format, |
| 240 GLenum type, | 240 GLenum type, |
| 241 const void* pixels) OVERRIDE { | 241 const void* pixels) override { |
| 242 CheckTextureIsBound(target); | 242 CheckTextureIsBound(target); |
| 243 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); | 243 ASSERT_EQ(static_cast<unsigned>(GL_TEXTURE_2D), target); |
| 244 ASSERT_FALSE(level); | 244 ASSERT_FALSE(level); |
| 245 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); | 245 ASSERT_EQ(static_cast<unsigned>(GL_UNSIGNED_BYTE), type); |
| 246 { | 246 { |
| 247 base::AutoLock lock_for_texture_access(namespace_->lock); | 247 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 248 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); | 248 ASSERT_EQ(GLDataFormat(BoundTexture(target)->format), format); |
| 249 } | 249 } |
| 250 ASSERT_TRUE(pixels); | 250 ASSERT_TRUE(pixels); |
| 251 SetPixels(xoffset, yoffset, width, height, pixels); | 251 SetPixels(xoffset, yoffset, width, height, pixels); |
| 252 } | 252 } |
| 253 | 253 |
| 254 virtual void genMailboxCHROMIUM(GLbyte* mailbox) OVERRIDE { | 254 virtual void genMailboxCHROMIUM(GLbyte* mailbox) override { |
| 255 return shared_data_->GenMailbox(mailbox); | 255 return shared_data_->GenMailbox(mailbox); |
| 256 } | 256 } |
| 257 | 257 |
| 258 virtual void produceTextureCHROMIUM(GLenum target, | 258 virtual void produceTextureCHROMIUM(GLenum target, |
| 259 const GLbyte* mailbox) OVERRIDE { | 259 const GLbyte* mailbox) override { |
| 260 CheckTextureIsBound(target); | 260 CheckTextureIsBound(target); |
| 261 | 261 |
| 262 // Delay moving the texture into the mailbox until the next | 262 // Delay moving the texture into the mailbox until the next |
| 263 // InsertSyncPoint, so that it is not visible to other contexts that | 263 // InsertSyncPoint, so that it is not visible to other contexts that |
| 264 // haven't waited on that sync point. | 264 // haven't waited on that sync point. |
| 265 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); | 265 scoped_ptr<PendingProduceTexture> pending(new PendingProduceTexture); |
| 266 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); | 266 memcpy(pending->mailbox, mailbox, sizeof(pending->mailbox)); |
| 267 base::AutoLock lock_for_texture_access(namespace_->lock); | 267 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 268 pending->texture = BoundTexture(target); | 268 pending->texture = BoundTexture(target); |
| 269 pending_produce_textures_.push_back(pending.Pass()); | 269 pending_produce_textures_.push_back(pending.Pass()); |
| 270 } | 270 } |
| 271 | 271 |
| 272 virtual void consumeTextureCHROMIUM(GLenum target, | 272 virtual void consumeTextureCHROMIUM(GLenum target, |
| 273 const GLbyte* mailbox) OVERRIDE { | 273 const GLbyte* mailbox) override { |
| 274 CheckTextureIsBound(target); | 274 CheckTextureIsBound(target); |
| 275 base::AutoLock lock_for_texture_access(namespace_->lock); | 275 base::AutoLock lock_for_texture_access(namespace_->lock); |
| 276 scoped_refptr<TestTexture> texture = | 276 scoped_refptr<TestTexture> texture = |
| 277 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); | 277 shared_data_->ConsumeTexture(mailbox, last_waited_sync_point_); |
| 278 namespace_->textures.Replace(BoundTextureId(target), texture); | 278 namespace_->textures.Replace(BoundTextureId(target), texture); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void GetPixels(const gfx::Size& size, | 281 void GetPixels(const gfx::Size& size, |
| 282 ResourceFormat format, | 282 ResourceFormat format, |
| 283 uint8_t* pixels) { | 283 uint8_t* pixels) { |
| (...skipping 3324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3608 resource_provider->DeleteResource(id); | 3608 resource_provider->DeleteResource(id); |
| 3609 } | 3609 } |
| 3610 | 3610 |
| 3611 INSTANTIATE_TEST_CASE_P( | 3611 INSTANTIATE_TEST_CASE_P( |
| 3612 ResourceProviderTests, | 3612 ResourceProviderTests, |
| 3613 ResourceProviderTest, | 3613 ResourceProviderTest, |
| 3614 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); | 3614 ::testing::Values(ResourceProvider::GLTexture, ResourceProvider::Bitmap)); |
| 3615 | 3615 |
| 3616 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { | 3616 class TextureIdAllocationTrackingContext : public TestWebGraphicsContext3D { |
| 3617 public: | 3617 public: |
| 3618 virtual GLuint NextTextureId() OVERRIDE { | 3618 virtual GLuint NextTextureId() override { |
| 3619 base::AutoLock lock(namespace_->lock); | 3619 base::AutoLock lock(namespace_->lock); |
| 3620 return namespace_->next_texture_id++; | 3620 return namespace_->next_texture_id++; |
| 3621 } | 3621 } |
| 3622 virtual void RetireTextureId(GLuint) OVERRIDE {} | 3622 virtual void RetireTextureId(GLuint) override {} |
| 3623 GLuint PeekTextureId() { | 3623 GLuint PeekTextureId() { |
| 3624 base::AutoLock lock(namespace_->lock); | 3624 base::AutoLock lock(namespace_->lock); |
| 3625 return namespace_->next_texture_id; | 3625 return namespace_->next_texture_id; |
| 3626 } | 3626 } |
| 3627 }; | 3627 }; |
| 3628 | 3628 |
| 3629 TEST(ResourceProviderTest, TextureAllocationChunkSize) { | 3629 TEST(ResourceProviderTest, TextureAllocationChunkSize) { |
| 3630 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( | 3630 scoped_ptr<TextureIdAllocationTrackingContext> context_owned( |
| 3631 new TextureIdAllocationTrackingContext); | 3631 new TextureIdAllocationTrackingContext); |
| 3632 TextureIdAllocationTrackingContext* context = context_owned.get(); | 3632 TextureIdAllocationTrackingContext* context = context_owned.get(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3677 resource_provider->AllocateForTesting(id); | 3677 resource_provider->AllocateForTesting(id); |
| 3678 Mock::VerifyAndClearExpectations(context); | 3678 Mock::VerifyAndClearExpectations(context); |
| 3679 | 3679 |
| 3680 DCHECK_EQ(10u, context->PeekTextureId()); | 3680 DCHECK_EQ(10u, context->PeekTextureId()); |
| 3681 resource_provider->DeleteResource(id); | 3681 resource_provider->DeleteResource(id); |
| 3682 } | 3682 } |
| 3683 } | 3683 } |
| 3684 | 3684 |
| 3685 } // namespace | 3685 } // namespace |
| 3686 } // namespace cc | 3686 } // namespace cc |
| OLD | NEW |