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

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

Issue 2565323003: Move gif image decoder to SkCodec (Closed)
Patch Set: More code review comments Created 3 years, 7 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) 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc. 3 * Copyright (C) 2008, 2009 Google, Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 void ImageFrame::ZeroFillPixelData() { 77 void ImageFrame::ZeroFillPixelData() {
78 bitmap_.eraseARGB(0, 0, 0, 0); 78 bitmap_.eraseARGB(0, 0, 0, 0);
79 has_alpha_ = true; 79 has_alpha_ = true;
80 } 80 }
81 81
82 bool ImageFrame::CopyBitmapData(const ImageFrame& other) { 82 bool ImageFrame::CopyBitmapData(const ImageFrame& other) {
83 DCHECK_NE(this, &other); 83 DCHECK_NE(this, &other);
84 has_alpha_ = other.has_alpha_; 84 has_alpha_ = other.has_alpha_;
85 bitmap_.reset(); 85 bitmap_.reset();
86 return other.bitmap_.copyTo(&bitmap_, other.bitmap_.colorType()); 86 bool copied = other.bitmap_.copyTo(&bitmap_, other.bitmap_.colorType());
87 if (copied)
88 status_ = kFrameAllocated;
89
90 return copied;
87 } 91 }
88 92
89 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) { 93 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) {
90 DCHECK(other); 94 DCHECK(other);
91 DCHECK_EQ(kFrameComplete, other->status_); 95 DCHECK_EQ(kFrameComplete, other->status_);
92 DCHECK_EQ(kFrameEmpty, status_); 96 DCHECK_EQ(kFrameEmpty, status_);
93 DCHECK_NE(this, other); 97 DCHECK_NE(this, other);
94 if (other->bitmap_.isImmutable()) 98 if (other->bitmap_.isImmutable())
95 return false; 99 return false;
96 has_alpha_ = other->has_alpha_; 100 has_alpha_ = other->has_alpha_;
97 bitmap_.reset(); 101 bitmap_.reset();
98 bitmap_.swap(other->bitmap_); 102 bitmap_.swap(other->bitmap_);
99 other->status_ = kFrameEmpty; 103 other->status_ = kFrameEmpty;
104 status_ = kFrameAllocated;
100 return true; 105 return true;
101 } 106 }
102 107
103 bool ImageFrame::AllocatePixelData(int new_width, 108 bool ImageFrame::AllocatePixelData(int new_width,
104 int new_height, 109 int new_height,
105 sk_sp<SkColorSpace> color_space) { 110 sk_sp<SkColorSpace> color_space) {
106 // allocatePixelData() should only be called once. 111 // allocatePixelData() should only be called once.
107 DCHECK(!Width() && !Height()); 112 DCHECK(!Width() && !Height());
108 113
109 bitmap_.setInfo(SkImageInfo::MakeN32( 114 bitmap_.setInfo(SkImageInfo::MakeN32(
110 new_width, new_height, 115 new_width, new_height,
111 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 116 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType,
112 std::move(color_space))); 117 std::move(color_space)));
113 return bitmap_.tryAllocPixels(allocator_, 0); 118 bool allocated = bitmap_.tryAllocPixels(allocator_, 0);
119 if (allocated)
120 status_ = kFrameAllocated;
121
122 return allocated;
114 } 123 }
115 124
116 bool ImageFrame::HasAlpha() const { 125 bool ImageFrame::HasAlpha() const {
117 return has_alpha_; 126 return has_alpha_;
118 } 127 }
119 128
120 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() { 129 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() {
121 DCHECK_EQ(kFrameComplete, status_); 130 DCHECK_EQ(kFrameComplete, status_);
122 bitmap_.setImmutable(); 131 bitmap_.setImmutable();
123 return SkImage::MakeFromBitmap(bitmap_); 132 return SkImage::MakeFromBitmap(bitmap_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // If the frame is not fully loaded, there will be transparent pixels, 208 // If the frame is not fully loaded, there will be transparent pixels,
200 // so we can't tell skia we're opaque, even for image types that logically 209 // so we can't tell skia we're opaque, even for image types that logically
201 // always are (e.g. jpeg). 210 // always are (e.g. jpeg).
202 if (!has_alpha_ && status_ == kFrameComplete) 211 if (!has_alpha_ && status_ == kFrameComplete)
203 return kOpaque_SkAlphaType; 212 return kOpaque_SkAlphaType;
204 213
205 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 214 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
206 } 215 }
207 216
208 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698