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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 284 |
285 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) | 285 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) |
286 return false; | 286 return false; |
287 | 287 |
288 if (purge_aggressively_) | 288 if (purge_aggressively_) |
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 < frame_buffer_cache_.size()); | |
296 ImageFrame& buffer = frame_buffer_cache_[index]; | |
297 | |
298 // When this frame spans the entire image rect we can SetHasAlpha 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 SetHasAlpha 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 |prev_buffer| is DisposeNotSpecified or DisposeKeep, |buffer| has no | |
319 // alpha if |prev_buffer| 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 |prev_buffer| | |
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 |prev_buffer|, which is | |
331 // too computationally expensive. | |
332 const ImageFrame* prev_buffer = | |
333 &frame_buffer_cache_[buffer.RequiredPreviousFrameIndex()]; | |
334 DCHECK(prev_buffer->GetDisposalMethod() != | |
335 ImageFrame::kDisposeOverwritePrevious); | |
336 | |
337 if ((prev_buffer->GetDisposalMethod() == | |
338 ImageFrame::kDisposeOverwriteBgcolor) && | |
339 !prev_buffer->HasAlpha() && | |
340 buffer.OriginalFrameRect().Contains(prev_buffer->OriginalFrameRect())) | |
341 buffer.SetHasAlpha(false); | |
342 } | |
343 } | |
344 | |
345 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { | 294 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { |
346 DCHECK(frame_index < frame_buffer_cache_.size()); | 295 DCHECK(frame_index < frame_buffer_cache_.size()); |
347 | 296 |
348 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; | 297 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; |
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::kFrameEmpty) | 300 if (buffer->GetStatus() != ImageFrame::kFrameEmpty) |
352 return true; | 301 return true; |
353 | 302 |
354 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); | 303 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 } | 526 } |
578 | 527 |
579 // For color spaces without an identifiable gamut, just fall through to | 528 // For color spaces without an identifiable gamut, just fall through to |
580 // sRGB. | 529 // sRGB. |
581 } | 530 } |
582 | 531 |
583 return SkColorSpace::MakeSRGB(); | 532 return SkColorSpace::MakeSRGB(); |
584 } | 533 } |
585 | 534 |
586 } // namespace blink | 535 } // namespace blink |
OLD | NEW |