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

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

Issue 2565323003: Move gif image decoder to SkCodec (Closed)
Patch Set: Only include SkCodec for non-iOS targets Created 3 years, 6 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 bool copied = false;
scroggo_chromium 2017/06/05 19:00:53 nit: My preference would be to drop this local var
cblume 2017/06/06 04:04:35 Done.
86 SkImageInfo info = other.bitmap_.info(); 87 SkImageInfo info = other.bitmap_.info();
87 return bitmap_.tryAllocPixels(info) && 88 if (bitmap_.tryAllocPixels(info)) {
88 other.bitmap_.readPixels(info, bitmap_.getPixels(), bitmap_.rowBytes(), 89 status_ = kFrameAllocated;
scroggo_chromium 2017/06/05 19:00:53 So if we fail in readPixels, we'll still have the
cblume 2017/06/06 04:04:35 Right. At that point we *have* allocated (with try
89 0, 0); 90 copied = other.bitmap_.readPixels(info, bitmap_.getPixels(),
91 bitmap_.rowBytes(), 0, 0);
92 }
93
94 return copied;
90 } 95 }
91 96
92 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) { 97 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) {
93 DCHECK(other); 98 DCHECK(other);
94 DCHECK_EQ(kFrameComplete, other->status_); 99 DCHECK_EQ(kFrameComplete, other->status_);
95 DCHECK_EQ(kFrameEmpty, status_); 100 DCHECK_EQ(kFrameEmpty, status_);
96 DCHECK_NE(this, other); 101 DCHECK_NE(this, other);
97 if (other->bitmap_.isImmutable()) 102 if (other->bitmap_.isImmutable())
98 return false; 103 return false;
99 has_alpha_ = other->has_alpha_; 104 has_alpha_ = other->has_alpha_;
100 bitmap_.reset(); 105 bitmap_.reset();
101 bitmap_.swap(other->bitmap_); 106 bitmap_.swap(other->bitmap_);
102 other->status_ = kFrameEmpty; 107 other->status_ = kFrameEmpty;
108 status_ = kFrameAllocated;
103 return true; 109 return true;
104 } 110 }
105 111
106 bool ImageFrame::AllocatePixelData(int new_width, 112 bool ImageFrame::AllocatePixelData(int new_width,
107 int new_height, 113 int new_height,
108 sk_sp<SkColorSpace> color_space) { 114 sk_sp<SkColorSpace> color_space) {
109 // AllocatePixelData() should only be called once. 115 // AllocatePixelData() should only be called once.
110 DCHECK(!Width() && !Height()); 116 DCHECK(!Width() && !Height());
111 117
112 bitmap_.setInfo(SkImageInfo::MakeN32( 118 bitmap_.setInfo(SkImageInfo::MakeN32(
113 new_width, new_height, 119 new_width, new_height,
114 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 120 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType,
115 std::move(color_space))); 121 std::move(color_space)));
116 return bitmap_.tryAllocPixels(allocator_, 0); 122 bool allocated = bitmap_.tryAllocPixels(allocator_, 0);
123 if (allocated)
124 status_ = kFrameAllocated;
125
126 return allocated;
117 } 127 }
118 128
119 bool ImageFrame::HasAlpha() const { 129 bool ImageFrame::HasAlpha() const {
120 return has_alpha_; 130 return has_alpha_;
121 } 131 }
122 132
123 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() { 133 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() {
124 DCHECK_EQ(kFrameComplete, status_); 134 DCHECK_EQ(kFrameComplete, status_);
125 bitmap_.setImmutable(); 135 bitmap_.setImmutable();
126 return SkImage::MakeFromBitmap(bitmap_); 136 return SkImage::MakeFromBitmap(bitmap_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // If the frame is not fully loaded, there will be transparent pixels, 212 // If the frame is not fully loaded, there will be transparent pixels,
203 // so we can't tell skia we're opaque, even for image types that logically 213 // so we can't tell skia we're opaque, even for image types that logically
204 // always are (e.g. jpeg). 214 // always are (e.g. jpeg).
205 if (!has_alpha_ && status_ == kFrameComplete) 215 if (!has_alpha_ && status_ == kFrameComplete)
206 return kOpaque_SkAlphaType; 216 return kOpaque_SkAlphaType;
207 217
208 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 218 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
209 } 219 }
210 220
211 } // namespace blink 221 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698