OLD | NEW |
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 | 290 |
291 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) | 291 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) |
292 return false; | 292 return false; |
293 | 293 |
294 if (purge_aggressively_) | 294 if (purge_aggressively_) |
295 ClearCacheExceptFrame(index); | 295 ClearCacheExceptFrame(index); |
296 | 296 |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 void ImageDecoder::CorrectAlphaWhenFrameBufferSawNoAlpha(size_t index) { | |
301 DCHECK(index < frame_buffer_cache_.size()); | |
302 ImageFrame& buffer = frame_buffer_cache_[index]; | |
303 | |
304 // When this frame spans the entire image rect we can SetHasAlpha to false, | |
305 // since there are logically no transparent pixels outside of the frame rect. | |
306 if (buffer.OriginalFrameRect().Contains(IntRect(IntPoint(), Size()))) { | |
307 buffer.SetHasAlpha(false); | |
308 buffer.SetRequiredPreviousFrameIndex(kNotFound); | |
309 } else if (buffer.RequiredPreviousFrameIndex() != kNotFound) { | |
310 // When the frame rect does not span the entire image rect, and it does | |
311 // *not* have a required previous frame, the pixels outside of the frame | |
312 // rect will be fully transparent, so we shoudn't SetHasAlpha to false. | |
313 // | |
314 // It is a tricky case when the frame does have a required previous frame. | |
315 // The frame does not have alpha only if everywhere outside its rect | |
316 // doesn't have alpha. To know whether this is true, we check the start | |
317 // state of the frame -- if it doesn't have alpha, we're safe. | |
318 // | |
319 // We first check that the required previous frame does not have | |
320 // DisposeOverWritePrevious as its disposal method - this should never | |
321 // happen, since the required frame should in that case be the required | |
322 // frame of this frame's required frame. | |
323 // | |
324 // If |prev_buffer| is DisposeNotSpecified or DisposeKeep, |buffer| has no | |
325 // alpha if |prev_buffer| had no alpha. Since InitFrameBuffer() already | |
326 // copied the alpha state, there's nothing to do here. | |
327 // | |
328 // The only remaining case is a DisposeOverwriteBgcolor frame. If | |
329 // it had no alpha, and its rect is contained in the current frame's | |
330 // rect, we know the current frame has no alpha. | |
331 // | |
332 // For DisposeNotSpecified, DisposeKeep and DisposeOverwriteBgcolor there | |
333 // is one situation that is not taken into account - when |prev_buffer| | |
334 // *does* have alpha, but only in the frame rect of |buffer|, we can still | |
335 // say that this frame has no alpha. However, to determine this, we | |
336 // potentially need to analyze all image pixels of |prev_buffer|, which is | |
337 // too computationally expensive. | |
338 const ImageFrame* prev_buffer = | |
339 &frame_buffer_cache_[buffer.RequiredPreviousFrameIndex()]; | |
340 DCHECK(prev_buffer->GetDisposalMethod() != | |
341 ImageFrame::kDisposeOverwritePrevious); | |
342 | |
343 if ((prev_buffer->GetDisposalMethod() == | |
344 ImageFrame::kDisposeOverwriteBgcolor) && | |
345 !prev_buffer->HasAlpha() && | |
346 buffer.OriginalFrameRect().Contains(prev_buffer->OriginalFrameRect())) | |
347 buffer.SetHasAlpha(false); | |
348 } | |
349 } | |
350 | |
351 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { | 300 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { |
352 DCHECK(frame_index < frame_buffer_cache_.size()); | 301 DCHECK(frame_index < frame_buffer_cache_.size()); |
353 | 302 |
354 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; | 303 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; |
355 | 304 |
356 // If the frame is already initialized, return true. | 305 // If the frame is already initialized, return true. |
357 if (buffer->GetStatus() != ImageFrame::kFrameEmpty) | 306 if (buffer->GetStatus() != ImageFrame::kFrameEmpty) |
358 return true; | 307 return true; |
359 | 308 |
360 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); | 309 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 539 } |
591 | 540 |
592 // For color spaces without an identifiable gamut, just fall through to | 541 // For color spaces without an identifiable gamut, just fall through to |
593 // sRGB. | 542 // sRGB. |
594 } | 543 } |
595 | 544 |
596 return SkColorSpace::MakeSRGB(); | 545 return SkColorSpace::MakeSRGB(); |
597 } | 546 } |
598 | 547 |
599 } // namespace blink | 548 } // namespace blink |
OLD | NEW |