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

Side by Side Diff: third_party/WebKit/Source/platform/image-decoders/ImageDecoder.cpp

Issue 2756463003: Remove opaque alpha channel special case (Closed)
Patch Set: Created 3 years, 9 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) Research In Motion Limited 2009-2010. All rights reserved. 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 if (m_frameBufferCache[index].getStatus() != ImageFrame::FrameComplete) 285 if (m_frameBufferCache[index].getStatus() != ImageFrame::FrameComplete)
286 return false; 286 return false;
287 287
288 if (m_purgeAggressively) 288 if (m_purgeAggressively)
289 clearCacheExceptFrame(index); 289 clearCacheExceptFrame(index);
290 290
291 return true; 291 return true;
292 } 292 }
293 293
294 void ImageDecoder::correctAlphaWhenFrameBufferSawNoAlpha(size_t index) {
295 DCHECK(index < m_frameBufferCache.size());
296 ImageFrame& buffer = m_frameBufferCache[index];
297
298 // When this frame spans the entire image rect we can set hasAlpha to false,
299 // since there are logically no transparent pixels outside of the frame rect.
300 if (buffer.originalFrameRect().contains(IntRect(IntPoint(), size()))) {
301 buffer.setHasAlpha(false);
302 buffer.setRequiredPreviousFrameIndex(kNotFound);
303 } else if (buffer.requiredPreviousFrameIndex() != kNotFound) {
304 // When the frame rect does not span the entire image rect, and it does
305 // *not* have a required previous frame, the pixels outside of the frame
306 // rect will be fully transparent, so we shoudn't set hasAlpha to false.
307 //
308 // It is a tricky case when the frame does have a required previous frame.
309 // The frame does not have alpha only if everywhere outside its rect
310 // doesn't have alpha. To know whether this is true, we check the start
311 // state of the frame -- if it doesn't have alpha, we're safe.
312 //
313 // We first check that the required previous frame does not have
314 // DisposeOverWritePrevious as its disposal method - this should never
315 // happen, since the required frame should in that case be the required
316 // frame of this frame's required frame.
317 //
318 // If |prevBuffer| is DisposeNotSpecified or DisposeKeep, |buffer| has no
319 // alpha if |prevBuffer| had no alpha. Since initFrameBuffer() already
320 // copied the alpha state, there's nothing to do here.
321 //
322 // The only remaining case is a DisposeOverwriteBgcolor frame. If
323 // it had no alpha, and its rect is contained in the current frame's
324 // rect, we know the current frame has no alpha.
325 //
326 // For DisposeNotSpecified, DisposeKeep and DisposeOverwriteBgcolor there
327 // is one situation that is not taken into account - when |prevBuffer|
328 // *does* have alpha, but only in the frame rect of |buffer|, we can still
329 // say that this frame has no alpha. However, to determine this, we
330 // potentially need to analyze all image pixels of |prevBuffer|, which is
331 // too computationally expensive.
332 const ImageFrame* prevBuffer =
333 &m_frameBufferCache[buffer.requiredPreviousFrameIndex()];
334 DCHECK(prevBuffer->getDisposalMethod() !=
335 ImageFrame::DisposeOverwritePrevious);
336
337 if ((prevBuffer->getDisposalMethod() ==
338 ImageFrame::DisposeOverwriteBgcolor) &&
339 !prevBuffer->hasAlpha() &&
340 buffer.originalFrameRect().contains(prevBuffer->originalFrameRect()))
341 buffer.setHasAlpha(false);
342 }
343 }
344
345 bool ImageDecoder::initFrameBuffer(size_t frameIndex) { 294 bool ImageDecoder::initFrameBuffer(size_t frameIndex) {
346 DCHECK(frameIndex < m_frameBufferCache.size()); 295 DCHECK(frameIndex < m_frameBufferCache.size());
347 296
348 ImageFrame* const buffer = &m_frameBufferCache[frameIndex]; 297 ImageFrame* const buffer = &m_frameBufferCache[frameIndex];
349 298
350 // If the frame is already initialized, return true. 299 // If the frame is already initialized, return true.
351 if (buffer->getStatus() != ImageFrame::FrameEmpty) 300 if (buffer->getStatus() != ImageFrame::FrameEmpty)
352 return true; 301 return true;
353 302
354 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex(); 303 size_t requiredPreviousFrameIndex = buffer->requiredPreviousFrameIndex();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const { 497 sk_sp<SkColorSpace> ImageDecoder::colorSpaceForSkImages() const {
549 if (!m_colorBehavior.isTag()) 498 if (!m_colorBehavior.isTag())
550 return nullptr; 499 return nullptr;
551 500
552 if (m_embeddedColorSpace) 501 if (m_embeddedColorSpace)
553 return m_embeddedColorSpace; 502 return m_embeddedColorSpace;
554 return SkColorSpace::MakeSRGB(); 503 return SkColorSpace::MakeSRGB();
555 } 504 }
556 505
557 } // namespace blink 506 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698