From b5b50a07abb454abaf6ab46db20c6db6f5ecf9f6 Mon Sep 17 00:00:00 2001 From: "Takahiro.Aizawa" Date: Mon, 15 Jun 2015 02:52:46 -0700 Subject: SkGIFMovie: Fix corrupted background color The 'paintingColor' in onGetBitmap() was used to save the entire gif's background color while filling the 1st frame of a gif image, since it is 'static' qualified, so when re-entering this function for subsequent frames, this saved value will be used directly without re-obtaining it. But if asynchronous playing multi gif files in single process without being controlled, this 'static' will make the 'paintingColor' corrupted, because the different SkGIFMovie instances hold the same reference of 'paintingColor'. Signed-off-by: Lu Tong ; BUG=skia: Review URL: https://codereview.chromium.org/1184083002 --- src/images/SkMovie_gif.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/images') diff --git a/src/images/SkMovie_gif.cpp b/src/images/SkMovie_gif.cpp index 40e5520def..380aca499a 100644 --- a/src/images/SkMovie_gif.cpp +++ b/src/images/SkMovie_gif.cpp @@ -35,6 +35,7 @@ private: int fCurrIndex; int fLastDrawIndex; SkBitmap fBackup; + SkColor fPaintingColor; }; static int Decode(GifFileType* fileType, GifByteType* out, int size) { @@ -59,6 +60,7 @@ SkGIFMovie::SkGIFMovie(SkStream* stream) } fCurrIndex = -1; fLastDrawIndex = -1; + fPaintingColor = SkPackARGB32(0, 0, 0, 0); } SkGIFMovie::~SkGIFMovie() @@ -395,7 +397,6 @@ bool SkGIFMovie::onGetBitmap(SkBitmap* bm) bgColor = SkColorSetARGB(0xFF, col.Red, col.Green, col.Blue); } - static SkColor paintingColor = SkPackARGB32(0, 0, 0, 0); // draw each frames - not intelligent way for (int i = startIndex; i <= lastIndex; i++) { const SavedImage* cur = &fGIF->SavedImages[i]; @@ -404,17 +405,17 @@ bool SkGIFMovie::onGetBitmap(SkBitmap* bm) int disposal; getTransparencyAndDisposalMethod(cur, &trans, &disposal); if (!trans && gif->SColorMap != NULL) { - paintingColor = bgColor; + fPaintingColor = bgColor; } else { - paintingColor = SkColorSetARGB(0, 0, 0, 0); + fPaintingColor = SkColorSetARGB(0, 0, 0, 0); } - bm->eraseColor(paintingColor); - fBackup.eraseColor(paintingColor); + bm->eraseColor(fPaintingColor); + fBackup.eraseColor(fPaintingColor); } else { // Dispose previous frame before move to next frame. const SavedImage* prev = &fGIF->SavedImages[i-1]; - disposeFrameIfNeeded(bm, prev, cur, &fBackup, paintingColor); + disposeFrameIfNeeded(bm, prev, cur, &fBackup, fPaintingColor); } // Draw frame -- cgit v1.2.3