Commit a7c239cc authored by robertphillips's avatar robertphillips Committed by Commit bot

ImagePixelLocker now manually allocates SkPixmap

Skia is retracting the SkAutoPixmapStorage class. These are the only two uses of it in Chrome.

Review URL: https://codereview.chromium.org/1813483002

Cr-Commit-Position: refs/heads/master@{#381700}
parent 3dd85c4f
...@@ -345,8 +345,12 @@ TEST_F(DeferredImageDecoderTest, frameOpacity) ...@@ -345,8 +345,12 @@ TEST_F(DeferredImageDecoderTest, frameOpacity)
decoder->setData(*m_data, true); decoder->setData(*m_data, true);
SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1); SkImageInfo pixInfo = SkImageInfo::MakeN32Premul(1, 1);
SkAutoPixmapStorage pixels;
pixels.alloc(pixInfo); size_t rowBytes = pixInfo.minRowBytes();
size_t size = pixInfo.getSafeSize(rowBytes);
SkAutoMalloc storage(size);
SkPixmap pixmap(pixInfo, storage.get(), rowBytes);
// Before decoding, the frame is not known to be opaque. // Before decoding, the frame is not known to be opaque.
RefPtr<SkImage> frame = decoder->createFrameAtIndex(0); RefPtr<SkImage> frame = decoder->createFrameAtIndex(0);
...@@ -354,7 +358,7 @@ TEST_F(DeferredImageDecoderTest, frameOpacity) ...@@ -354,7 +358,7 @@ TEST_F(DeferredImageDecoderTest, frameOpacity)
EXPECT_FALSE(frame->isOpaque()); EXPECT_FALSE(frame->isOpaque());
// Force a lazy decode by reading pixels. // Force a lazy decode by reading pixels.
EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
// After decoding, the frame is known to be opaque. // After decoding, the frame is known to be opaque.
frame = decoder->createFrameAtIndex(0); frame = decoder->createFrameAtIndex(0);
...@@ -362,7 +366,7 @@ TEST_F(DeferredImageDecoderTest, frameOpacity) ...@@ -362,7 +366,7 @@ TEST_F(DeferredImageDecoderTest, frameOpacity)
EXPECT_TRUE(frame->isOpaque()); EXPECT_TRUE(frame->isOpaque());
// Re-generating the opaque-marked frame should not fail. // Re-generating the opaque-marked frame should not fail.
EXPECT_TRUE(frame->readPixels(pixels, 0, 0)); EXPECT_TRUE(frame->readPixels(pixmap, 0, 0));
} }
} // namespace blink } // namespace blink
...@@ -29,26 +29,35 @@ ImagePixelLocker::ImagePixelLocker(PassRefPtr<const SkImage> image, SkAlphaType ...@@ -29,26 +29,35 @@ ImagePixelLocker::ImagePixelLocker(PassRefPtr<const SkImage> image, SkAlphaType
: m_image(image) : m_image(image)
{ {
SkImageInfo info; SkImageInfo info;
size_t imageRowBytes; size_t rowBytes;
// If the image has in-RAM pixels and their format matches, use them directly. // If the image has in-RAM pixels and their format matches, use them directly.
// TODO(fmalita): All current clients expect packed pixel rows. Maybe we could update them // TODO(fmalita): All current clients expect packed pixel rows. Maybe we could update them
// to support arbitrary rowBytes, and relax the check below. // to support arbitrary rowBytes, and relax the check below.
m_pixels = m_image->peekPixels(&info, &imageRowBytes); m_pixels = m_image->peekPixels(&info, &rowBytes);
if (m_pixels if (m_pixels
&& infoIsCompatible(info, alphaType, colorType) && infoIsCompatible(info, alphaType, colorType)
&& imageRowBytes == info.minRowBytes()) { && rowBytes == info.minRowBytes()) {
return; return;
} }
m_pixels = nullptr;
// No luck, we need to read the pixels into our local buffer. // No luck, we need to read the pixels into our local buffer.
info = SkImageInfo::Make(m_image->width(), m_image->height(), colorType, alphaType); info = SkImageInfo::Make(m_image->width(), m_image->height(), colorType, alphaType);
if (!m_pixelStorage.tryAlloc(info) || !m_image->readPixels(m_pixelStorage, 0, 0)) { rowBytes = info.minRowBytes();
m_pixels = nullptr; size_t size = info.getSafeSize(rowBytes);
if (0 == size)
return;
m_pixelStorage.reset(size); // this will throw on failure
SkPixmap pixmap(info, m_pixelStorage.get(), rowBytes);
if (!m_image->readPixels(pixmap, 0, 0))
return; return;
}
m_pixels = m_pixelStorage.addr(); m_pixels = m_pixelStorage.get();
} }
} // namespace blink } // namespace blink
...@@ -28,7 +28,7 @@ public: ...@@ -28,7 +28,7 @@ public:
private: private:
const RefPtr<const SkImage> m_image; const RefPtr<const SkImage> m_image;
const void* m_pixels; const void* m_pixels;
SkAutoPixmapStorage m_pixelStorage; SkAutoMalloc m_pixelStorage;
}; };
} // namespace blink } // namespace blink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment