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

Side by Side Diff: Source/platform/graphics/ImageFrameGeneratorTest.cpp

Issue 794223003: Cheaper thread-safe atomic initialization of static references. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add type check for initial value Created 5 years, 11 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 { 45 {
46 return SkImageInfo::Make(100, 100, kBGRA_8888_SkColorType, kOpaque_SkAlphaTy pe); 46 return SkImageInfo::Make(100, 100, kBGRA_8888_SkColorType, kOpaque_SkAlphaTy pe);
47 } 47 }
48 48
49 } // namespace 49 } // namespace
50 50
51 class ImageFrameGeneratorTest : public ::testing::Test, public MockImageDecoderC lient { 51 class ImageFrameGeneratorTest : public ::testing::Test, public MockImageDecoderC lient {
52 public: 52 public:
53 virtual void SetUp() override 53 virtual void SetUp() override
54 { 54 {
55 ImageDecodingStore::instance()->setCacheLimitInBytes(1024 * 1024); 55 ImageDecodingStore::instance().setCacheLimitInBytes(1024 * 1024);
56 m_data = SharedBuffer::create(); 56 m_data = SharedBuffer::create();
57 m_generator = ImageFrameGenerator::create(fullSize(), m_data, false); 57 m_generator = ImageFrameGenerator::create(fullSize(), m_data, false);
58 useMockImageDecoderFactory(); 58 useMockImageDecoderFactory();
59 m_decodersDestroyed = 0; 59 m_decodersDestroyed = 0;
60 m_frameBufferRequestCount = 0; 60 m_frameBufferRequestCount = 0;
61 m_status = ImageFrame::FrameEmpty; 61 m_status = ImageFrame::FrameEmpty;
62 m_frameCount = 1; 62 m_frameCount = 1;
63 } 63 }
64 64
65 virtual void TearDown() override 65 virtual void TearDown() override
66 { 66 {
67 ImageDecodingStore::instance()->clear(); 67 ImageDecodingStore::instance().clear();
68 } 68 }
69 69
70 virtual void decoderBeingDestroyed() override 70 virtual void decoderBeingDestroyed() override
71 { 71 {
72 ++m_decodersDestroyed; 72 ++m_decodersDestroyed;
73 } 73 }
74 74
75 virtual void frameBufferRequested() override 75 virtual void frameBufferRequested() override
76 { 76 {
77 ++m_frameBufferRequestCount; 77 ++m_frameBufferRequestCount;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 TEST_F(ImageFrameGeneratorTest, frameHasAlpha) 188 TEST_F(ImageFrameGeneratorTest, frameHasAlpha)
189 { 189 {
190 setFrameStatus(ImageFrame::FramePartial); 190 setFrameStatus(ImageFrame::FramePartial);
191 191
192 char buffer[100 * 100 * 4]; 192 char buffer[100 * 100 * 4];
193 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 193 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
194 EXPECT_TRUE(m_generator->hasAlpha(0)); 194 EXPECT_TRUE(m_generator->hasAlpha(0));
195 EXPECT_EQ(1, m_frameBufferRequestCount); 195 EXPECT_EQ(1, m_frameBufferRequestCount);
196 196
197 ImageDecoder* tempDecoder = 0; 197 ImageDecoder* tempDecoder = 0;
198 EXPECT_TRUE(ImageDecodingStore::instance()->lockDecoder(m_generator.get(), f ullSize(), &tempDecoder)); 198 EXPECT_TRUE(ImageDecodingStore::instance().lockDecoder(m_generator.get(), fu llSize(), &tempDecoder));
199 ASSERT_TRUE(tempDecoder); 199 ASSERT_TRUE(tempDecoder);
200 static_cast<MockImageDecoder*>(tempDecoder)->setFrameHasAlpha(false); 200 static_cast<MockImageDecoder*>(tempDecoder)->setFrameHasAlpha(false);
201 ImageDecodingStore::instance()->unlockDecoder(m_generator.get(), tempDecoder ); 201 ImageDecodingStore::instance().unlockDecoder(m_generator.get(), tempDecoder) ;
202 202
203 setFrameStatus(ImageFrame::FrameComplete); 203 setFrameStatus(ImageFrame::FrameComplete);
204 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4); 204 m_generator->decodeAndScale(imageInfo(), 0, buffer, 100 * 4);
205 EXPECT_EQ(2, m_frameBufferRequestCount); 205 EXPECT_EQ(2, m_frameBufferRequestCount);
206 EXPECT_FALSE(m_generator->hasAlpha(0)); 206 EXPECT_FALSE(m_generator->hasAlpha(0));
207 } 207 }
208 208
209 TEST_F(ImageFrameGeneratorTest, removeMultiFrameDecoder) 209 TEST_F(ImageFrameGeneratorTest, removeMultiFrameDecoder)
210 { 210 {
211 setFrameCount(3); 211 setFrameCount(3);
(...skipping 12 matching lines...) Expand all
224 224
225 setFrameStatus(ImageFrame::FrameComplete); 225 setFrameStatus(ImageFrame::FrameComplete);
226 226
227 // Multi frame decoder should be removed. 227 // Multi frame decoder should be removed.
228 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4); 228 m_generator->decodeAndScale(imageInfo(), 2, buffer, 100 * 4);
229 EXPECT_EQ(3, m_frameBufferRequestCount); 229 EXPECT_EQ(3, m_frameBufferRequestCount);
230 EXPECT_EQ(1, m_decodersDestroyed); 230 EXPECT_EQ(1, m_decodersDestroyed);
231 } 231 }
232 232
233 } // namespace blink 233 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698