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

Side by Side Diff: third_party/WebKit/Source/platform/exported/WebImage.cpp

Issue 2155973002: Save a bitmap copy when advancing to dependent GIF and WebP animation frames (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: finalizePixelsAndGetImage. Created 4 years, 3 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) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 if (frameArea < (desiredSize.width * desiredSize.height)) 71 if (frameArea < (desiredSize.width * desiredSize.height))
72 break; // No more frames that are large enough. 72 break; // No more frames that are large enough.
73 73
74 if (!i || (frameArea < frameAreaAtIndex)) { 74 if (!i || (frameArea < frameAreaAtIndex)) {
75 index = i; // Closer to desired area than previous best match. 75 index = i; // Closer to desired area than previous best match.
76 frameAreaAtIndex = frameArea; 76 frameAreaAtIndex = frameArea;
77 } 77 }
78 } 78 }
79 79
80 ImageFrame* frame = decoder->frameBufferAtIndex(index); 80 ImageFrame* frame = decoder->frameBufferAtIndex(index);
81 if (!frame) 81 if (!frame || decoder->failed())
82 return WebImage(); 82 return WebImage();
83 83
84 return WebImage(frame->bitmap()); 84 DCHECK_EQ(frame->getStatus(), ImageFrame::FrameComplete);
85 SkBitmap bitmap = frame->bitmap();
86 bitmap.setImmutable();
87 return WebImage(bitmap);
85 } 88 }
86 89
87 WebVector<WebImage> WebImage::framesFromData(const WebData& data) 90 WebVector<WebImage> WebImage::framesFromData(const WebData& data)
88 { 91 {
89 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice. 92 // This is to protect from malicious images. It should be big enough that it 's never hit in pracice.
90 const size_t maxFrameCount = 8; 93 const size_t maxFrameCount = 8;
91 94
92 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data); 95 RefPtr<SharedBuffer> buffer = PassRefPtr<SharedBuffer>(data);
93 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder:: GammaAndColorProfileIgnored)); 96 std::unique_ptr<ImageDecoder> decoder(ImageDecoder::create(ImageDecoder::det ermineImageType(*buffer.get()), ImageDecoder::AlphaPremultiplied, ImageDecoder:: GammaAndColorProfileIgnored));
94 if (!decoder) 97 if (!decoder)
(...skipping 12 matching lines...) Expand all
107 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) { 110 for (size_t i = 0; i < std::min(frameCount, maxFrameCount); ++i) {
108 const IntSize frameSize = decoder->frameSizeAtIndex(i); 111 const IntSize frameSize = decoder->frameSizeAtIndex(i);
109 if (frameSize == lastSize) 112 if (frameSize == lastSize)
110 continue; 113 continue;
111 lastSize = frameSize; 114 lastSize = frameSize;
112 115
113 ImageFrame* frame = decoder->frameBufferAtIndex(i); 116 ImageFrame* frame = decoder->frameBufferAtIndex(i);
114 if (!frame) 117 if (!frame)
115 continue; 118 continue;
116 119
117 const SkBitmap& bitmap = frame->bitmap(); 120 SkBitmap bitmap = frame->bitmap();
118 if (!bitmap.isNull() && bitmap.isImmutable()) 121 if (!bitmap.isNull() && frame->getStatus() == ImageFrame::FrameComplete) {
122 bitmap.setImmutable();
119 frames.append(WebImage(bitmap)); 123 frames.append(WebImage(bitmap));
124 }
120 } 125 }
121 126
122 return frames; 127 return frames;
123 } 128 }
124 129
125 void WebImage::reset() 130 void WebImage::reset()
126 { 131 {
127 m_bitmap.reset(); 132 m_bitmap.reset();
128 } 133 }
129 134
(...skipping 15 matching lines...) Expand all
145 WebImage::WebImage(const PassRefPtr<Image>& image) 150 WebImage::WebImage(const PassRefPtr<Image>& image)
146 { 151 {
147 if (!image) 152 if (!image)
148 return; 153 return;
149 154
150 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame()) 155 if (RefPtr<SkImage> skImage = image->imageForCurrentFrame())
151 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode); 156 skImage->asLegacyBitmap(&m_bitmap, SkImage::kRO_LegacyBitmapMode);
152 } 157 }
153 158
154 } // namespace blink 159 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698