OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/gfx/image/image_skia.h" | 5 #include "ui/gfx/image/image_skia.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/threading/simple_thread.h" | 8 #include "base/threading/simple_thread.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/skia/include/core/SkBitmap.h" | 10 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 // so other thread cannot read/modify it. | 286 // so other thread cannot read/modify it. |
287 image.image_reps(); | 287 image.image_reps(); |
288 test::TestOnThread image_on_thread2(&image); | 288 test::TestOnThread image_on_thread2(&image); |
289 image_on_thread2.StartAndJoin(); | 289 image_on_thread2.StartAndJoin(); |
290 EXPECT_FALSE(image_on_thread2.can_read()); | 290 EXPECT_FALSE(image_on_thread2.can_read()); |
291 EXPECT_FALSE(image_on_thread2.can_modify()); | 291 EXPECT_FALSE(image_on_thread2.can_modify()); |
292 EXPECT_TRUE(image.CanRead()); | 292 EXPECT_TRUE(image.CanRead()); |
293 EXPECT_TRUE(image.CanModify()); | 293 EXPECT_TRUE(image.CanModify()); |
294 | 294 |
295 image.DetachStorageFromThread(); | 295 image.DetachStorageFromThread(); |
296 ImageSkia deep_copy = image.DeepCopy(); | 296 scoped_ptr<ImageSkia> deep_copy(image.DeepCopy()); |
297 EXPECT_FALSE(deep_copy.IsThreadSafe()); | 297 EXPECT_FALSE(deep_copy->IsThreadSafe()); |
298 test::TestOnThread deepcopy_on_thread(&deep_copy); | 298 test::TestOnThread deepcopy_on_thread(deep_copy.get()); |
299 deepcopy_on_thread.StartAndJoin(); | 299 deepcopy_on_thread.StartAndJoin(); |
300 EXPECT_TRUE(deepcopy_on_thread.can_read()); | 300 EXPECT_TRUE(deepcopy_on_thread.can_read()); |
301 EXPECT_TRUE(deepcopy_on_thread.can_modify()); | 301 EXPECT_TRUE(deepcopy_on_thread.can_modify()); |
302 EXPECT_FALSE(deep_copy.CanRead()); | 302 EXPECT_FALSE(deep_copy->CanRead()); |
303 EXPECT_FALSE(deep_copy.CanModify()); | 303 EXPECT_FALSE(deep_copy->CanModify()); |
304 | 304 |
305 ImageSkia deep_copy2 = image.DeepCopy(); | 305 scoped_ptr<ImageSkia> deep_copy2(image.DeepCopy()); |
306 EXPECT_EQ(1U, deep_copy2.image_reps().size()); | 306 EXPECT_EQ(1U, deep_copy2->image_reps().size()); |
307 // Access it from current thread so that it can't be | 307 // Access it from current thread so that it can't be |
308 // accessed from another thread. | 308 // accessed from another thread. |
309 deep_copy2.image_reps(); | 309 deep_copy2->image_reps(); |
310 EXPECT_FALSE(deep_copy2.IsThreadSafe()); | 310 EXPECT_FALSE(deep_copy2->IsThreadSafe()); |
311 test::TestOnThread deepcopy2_on_thread(&deep_copy2); | 311 test::TestOnThread deepcopy2_on_thread(deep_copy2.get()); |
312 deepcopy2_on_thread.StartAndJoin(); | 312 deepcopy2_on_thread.StartAndJoin(); |
313 EXPECT_FALSE(deepcopy2_on_thread.can_read()); | 313 EXPECT_FALSE(deepcopy2_on_thread.can_read()); |
314 EXPECT_FALSE(deepcopy2_on_thread.can_modify()); | 314 EXPECT_FALSE(deepcopy2_on_thread.can_modify()); |
315 EXPECT_TRUE(deep_copy2.CanRead()); | 315 EXPECT_TRUE(deep_copy2->CanRead()); |
316 EXPECT_TRUE(deep_copy2.CanModify()); | 316 EXPECT_TRUE(deep_copy2->CanModify()); |
317 | 317 |
318 image.DetachStorageFromThread(); | 318 image.DetachStorageFromThread(); |
319 image.SetReadOnly(); | 319 image.SetReadOnly(); |
320 // A read-only ImageSkia with no source is thread safe. | 320 // A read-only ImageSkia with no source is thread safe. |
321 EXPECT_TRUE(image.IsThreadSafe()); | 321 EXPECT_TRUE(image.IsThreadSafe()); |
322 test::TestOnThread readonly_on_thread(&image); | 322 test::TestOnThread readonly_on_thread(&image); |
323 readonly_on_thread.StartAndJoin(); | 323 readonly_on_thread.StartAndJoin(); |
324 EXPECT_TRUE(readonly_on_thread.can_read()); | 324 EXPECT_TRUE(readonly_on_thread.can_read()); |
325 EXPECT_FALSE(readonly_on_thread.can_modify()); | 325 EXPECT_FALSE(readonly_on_thread.can_modify()); |
326 EXPECT_TRUE(image.CanRead()); | 326 EXPECT_TRUE(image.CanRead()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 EXPECT_FALSE(threadsafe_on_thread.can_modify()); | 383 EXPECT_FALSE(threadsafe_on_thread.can_modify()); |
384 EXPECT_TRUE(image.CanRead()); | 384 EXPECT_TRUE(image.CanRead()); |
385 EXPECT_FALSE(image.CanModify()); | 385 EXPECT_FALSE(image.CanModify()); |
386 } | 386 } |
387 #endif // ENABLE_NON_THREAD_SAFE | 387 #endif // ENABLE_NON_THREAD_SAFE |
388 | 388 |
389 // Just in case we ever get lumped together with other compilation units. | 389 // Just in case we ever get lumped together with other compilation units. |
390 #undef ENABLE_NON_THREAD_SAFE | 390 #undef ENABLE_NON_THREAD_SAFE |
391 | 391 |
392 } // namespace gfx | 392 } // namespace gfx |
OLD | NEW |