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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) | 259 if (frame_buffer_cache_[index].GetStatus() != ImageFrame::kFrameComplete) |
260 return false; | 260 return false; |
261 | 261 |
262 if (purge_aggressively_) | 262 if (purge_aggressively_) |
263 ClearCacheExceptFrame(index); | 263 ClearCacheExceptFrame(index); |
264 | 264 |
265 return true; | 265 return true; |
266 } | 266 } |
267 | 267 |
268 void ImageDecoder::CorrectAlphaWhenFrameBufferSawNoAlpha(size_t index) { | |
269 DCHECK(index < frame_buffer_cache_.size()); | |
270 ImageFrame& buffer = frame_buffer_cache_[index]; | |
271 | |
272 // When this frame spans the entire image rect we can SetHasAlpha to false, | |
273 // since there are logically no transparent pixels outside of the frame rect. | |
274 if (buffer.OriginalFrameRect().Contains(IntRect(IntPoint(), Size()))) { | |
275 buffer.SetHasAlpha(false); | |
276 buffer.SetRequiredPreviousFrameIndex(kNotFound); | |
277 } else if (buffer.RequiredPreviousFrameIndex() != kNotFound) { | |
278 // When the frame rect does not span the entire image rect, and it does | |
279 // *not* have a required previous frame, the pixels outside of the frame | |
280 // rect will be fully transparent, so we shoudn't SetHasAlpha to false. | |
281 // | |
282 // It is a tricky case when the frame does have a required previous frame. | |
283 // The frame does not have alpha only if everywhere outside its rect | |
284 // doesn't have alpha. To know whether this is true, we check the start | |
285 // state of the frame -- if it doesn't have alpha, we're safe. | |
286 // | |
287 // We first check that the required previous frame does not have | |
288 // DisposeOverWritePrevious as its disposal method - this should never | |
289 // happen, since the required frame should in that case be the required | |
290 // frame of this frame's required frame. | |
291 // | |
292 // If |prev_buffer| is DisposeNotSpecified or DisposeKeep, |buffer| has no | |
293 // alpha if |prev_buffer| had no alpha. Since InitFrameBuffer() already | |
294 // copied the alpha state, there's nothing to do here. | |
295 // | |
296 // The only remaining case is a DisposeOverwriteBgcolor frame. If | |
297 // it had no alpha, and its rect is contained in the current frame's | |
298 // rect, we know the current frame has no alpha. | |
299 // | |
300 // For DisposeNotSpecified, DisposeKeep and DisposeOverwriteBgcolor there | |
301 // is one situation that is not taken into account - when |prev_buffer| | |
302 // *does* have alpha, but only in the frame rect of |buffer|, we can still | |
303 // say that this frame has no alpha. However, to determine this, we | |
304 // potentially need to analyze all image pixels of |prev_buffer|, which is | |
305 // too computationally expensive. | |
306 const ImageFrame* prev_buffer = | |
307 &frame_buffer_cache_[buffer.RequiredPreviousFrameIndex()]; | |
308 DCHECK(prev_buffer->GetDisposalMethod() != | |
309 ImageFrame::kDisposeOverwritePrevious); | |
310 | |
311 if ((prev_buffer->GetDisposalMethod() == | |
312 ImageFrame::kDisposeOverwriteBgcolor) && | |
313 !prev_buffer->HasAlpha() && | |
314 buffer.OriginalFrameRect().Contains(prev_buffer->OriginalFrameRect())) | |
315 buffer.SetHasAlpha(false); | |
316 } | |
317 } | |
318 | |
319 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { | 268 bool ImageDecoder::InitFrameBuffer(size_t frame_index) { |
320 DCHECK(frame_index < frame_buffer_cache_.size()); | 269 DCHECK(frame_index < frame_buffer_cache_.size()); |
321 | 270 |
322 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; | 271 ImageFrame* const buffer = &frame_buffer_cache_[frame_index]; |
323 | 272 |
324 // If the frame is already initialized, return true. | 273 // If the frame is already initialized, return true. |
325 if (buffer->GetStatus() != ImageFrame::kFrameEmpty) | 274 if (buffer->GetStatus() != ImageFrame::kFrameEmpty) |
326 return true; | 275 return true; |
327 | 276 |
328 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); | 277 size_t required_previous_frame_index = buffer->RequiredPreviousFrameIndex(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 } | 507 } |
559 | 508 |
560 // For color spaces without an identifiable gamut, just fall through to | 509 // For color spaces without an identifiable gamut, just fall through to |
561 // sRGB. | 510 // sRGB. |
562 } | 511 } |
563 | 512 |
564 return SkColorSpace::MakeSRGB(); | 513 return SkColorSpace::MakeSRGB(); |
565 } | 514 } |
566 | 515 |
567 } // namespace blink | 516 } // namespace blink |
OLD | NEW |