| OLD | NEW |
| 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 19 matching lines...) Expand all Loading... |
| 30 #include <gtest/gtest.h> | 30 #include <gtest/gtest.h> |
| 31 #include "MockImageDecoder.h" | 31 #include "MockImageDecoder.h" |
| 32 #include "SkCanvas.h" | 32 #include "SkCanvas.h" |
| 33 #include "SkDevice.h" | 33 #include "SkDevice.h" |
| 34 #include "SkPicture.h" | 34 #include "SkPicture.h" |
| 35 #include "core/platform/SharedBuffer.h" | 35 #include "core/platform/SharedBuffer.h" |
| 36 #include "core/platform/graphics/chromium/ImageDecodingStore.h" | 36 #include "core/platform/graphics/chromium/ImageDecodingStore.h" |
| 37 #include "core/platform/graphics/skia/NativeImageSkia.h" | 37 #include "core/platform/graphics/skia/NativeImageSkia.h" |
| 38 #include <wtf/PassRefPtr.h> | 38 #include <wtf/PassRefPtr.h> |
| 39 #include <wtf/RefPtr.h> | 39 #include <wtf/RefPtr.h> |
| 40 #include <wtf/Threading.h> | |
| 41 | 40 |
| 42 using namespace WebCore; | 41 using namespace WebCore; |
| 43 | 42 |
| 44 namespace { | 43 namespace { |
| 45 | 44 |
| 46 // Raw data for a PNG file with 1x1 white pixels. | 45 // Raw data for a PNG file with 1x1 white pixels. |
| 47 const unsigned char whitePNG[] = { | 46 const unsigned char whitePNG[] = { |
| 48 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, | 47 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, |
| 49 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, | 48 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, |
| 50 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, | 49 0x00, 0x00, 0x00, 0x01, 0x08, 0x02, 0x00, 0x00, 0x00, 0x90, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 164 } |
| 166 | 165 |
| 167 static void rasterizeMain(void* arg) | 166 static void rasterizeMain(void* arg) |
| 168 { | 167 { |
| 169 Rasterizer* rasterizer = static_cast<Rasterizer*>(arg); | 168 Rasterizer* rasterizer = static_cast<Rasterizer*>(arg); |
| 170 rasterizer->canvas->drawPicture(*rasterizer->picture); | 169 rasterizer->canvas->drawPicture(*rasterizer->picture); |
| 171 } | 170 } |
| 172 | 171 |
| 173 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) | 172 TEST_F(DeferredImageDecoderTest, decodeOnOtherThread) |
| 174 { | 173 { |
| 175 WTF::initializeThreading(); | |
| 176 | |
| 177 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); | 174 RefPtr<NativeImageSkia> image = m_lazyDecoder->frameBufferAtIndex(0)->asNewN
ativeImage(); |
| 178 EXPECT_EQ(1, image->bitmap().width()); | 175 EXPECT_EQ(1, image->bitmap().width()); |
| 179 EXPECT_EQ(1, image->bitmap().height()); | 176 EXPECT_EQ(1, image->bitmap().height()); |
| 180 EXPECT_FALSE(image->bitmap().isNull()); | 177 EXPECT_FALSE(image->bitmap().isNull()); |
| 181 EXPECT_TRUE(image->bitmap().isImmutable()); | 178 EXPECT_TRUE(image->bitmap().isImmutable()); |
| 182 | 179 |
| 183 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); | 180 SkCanvas* tempCanvas = m_picture.beginRecording(100, 100); |
| 184 tempCanvas->drawBitmap(image->bitmap(), 0, 0); | 181 tempCanvas->drawBitmap(image->bitmap(), 0, 0); |
| 185 m_picture.endRecording(); | 182 m_picture.endRecording(); |
| 186 EXPECT_EQ(0, m_frameBufferRequestCount); | 183 EXPECT_EQ(0, m_frameBufferRequestCount); |
| 187 | 184 |
| 188 // Create a thread to rasterize SkPicture. | 185 // Create a thread to rasterize SkPicture. |
| 189 Rasterizer rasterizer; | 186 Rasterizer rasterizer; |
| 190 rasterizer.canvas = m_canvas; | 187 rasterizer.canvas = m_canvas; |
| 191 rasterizer.picture = &m_picture; | 188 rasterizer.picture = &m_picture; |
| 192 ThreadIdentifier threadID = createThread(&rasterizeMain, &rasterizer, "Raste
rThread"); | 189 ThreadIdentifier threadID = createThread(&rasterizeMain, &rasterizer, "Raste
rThread"); |
| 193 waitForThreadCompletion(threadID); | 190 waitForThreadCompletion(threadID); |
| 194 EXPECT_EQ(0, m_frameBufferRequestCount); | 191 EXPECT_EQ(0, m_frameBufferRequestCount); |
| 195 | 192 |
| 196 SkBitmap canvasBitmap; | 193 SkBitmap canvasBitmap; |
| 197 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); | 194 canvasBitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 100); |
| 198 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); | 195 ASSERT_TRUE(m_canvas->readPixels(&canvasBitmap, 0, 0)); |
| 199 SkAutoLockPixels autoLock(canvasBitmap); | 196 SkAutoLockPixels autoLock(canvasBitmap); |
| 200 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); | 197 EXPECT_EQ(SkColorSetARGB(255, 255, 255, 255), canvasBitmap.getColor(0, 0)); |
| 201 } | 198 } |
| 202 | 199 |
| 203 } // namespace | 200 } // namespace |
| OLD | NEW |