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

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

Issue 2565323003: Move gif image decoder to SkCodec (Closed)
Patch Set: Explicitly specify move ctor / assignment until required patch lands. Created 3 years, 4 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SkImageInfo info = other.bitmap_.info(); 86 SkImageInfo info = other.bitmap_.info();
87 return bitmap_.tryAllocPixels(info) && 87 if (!bitmap_.tryAllocPixels(info)) {
88 other.bitmap_.readPixels(info, bitmap_.getPixels(), bitmap_.rowBytes(), 88 return false;
89 }
90
91 status_ = kFrameAllocated;
92 return other.bitmap_.readPixels(info, bitmap_.getPixels(), bitmap_.rowBytes(),
89 0, 0); 93 0, 0);
90 } 94 }
91 95
92 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) { 96 bool ImageFrame::TakeBitmapDataIfWritable(ImageFrame* other) {
93 DCHECK(other); 97 DCHECK(other);
94 DCHECK_EQ(kFrameComplete, other->status_); 98 DCHECK_EQ(kFrameComplete, other->status_);
95 DCHECK_EQ(kFrameEmpty, status_); 99 DCHECK_EQ(kFrameEmpty, status_);
96 DCHECK_NE(this, other); 100 DCHECK_NE(this, other);
97 if (other->bitmap_.isImmutable()) 101 if (other->bitmap_.isImmutable())
98 return false; 102 return false;
99 has_alpha_ = other->has_alpha_; 103 has_alpha_ = other->has_alpha_;
100 bitmap_.reset(); 104 bitmap_.reset();
101 bitmap_.swap(other->bitmap_); 105 bitmap_.swap(other->bitmap_);
102 other->status_ = kFrameEmpty; 106 other->status_ = kFrameEmpty;
107 status_ = kFrameAllocated;
103 return true; 108 return true;
104 } 109 }
105 110
106 bool ImageFrame::AllocatePixelData(int new_width, 111 bool ImageFrame::AllocatePixelData(int new_width,
107 int new_height, 112 int new_height,
108 sk_sp<SkColorSpace> color_space) { 113 sk_sp<SkColorSpace> color_space) {
109 // AllocatePixelData() should only be called once. 114 // AllocatePixelData() should only be called once.
110 DCHECK(!Width() && !Height()); 115 DCHECK(!Width() && !Height());
111 116
112 bitmap_.setInfo(SkImageInfo::MakeN32( 117 bitmap_.setInfo(SkImageInfo::MakeN32(
113 new_width, new_height, 118 new_width, new_height,
114 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 119 premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType,
115 std::move(color_space))); 120 std::move(color_space)));
116 return bitmap_.tryAllocPixels(allocator_); 121 bool allocated = bitmap_.tryAllocPixels(allocator_);
122 if (allocated)
123 status_ = kFrameAllocated;
124
125 return allocated;
117 } 126 }
118 127
119 bool ImageFrame::HasAlpha() const { 128 bool ImageFrame::HasAlpha() const {
120 return has_alpha_; 129 return has_alpha_;
121 } 130 }
122 131
123 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() { 132 sk_sp<SkImage> ImageFrame::FinalizePixelsAndGetImage() {
124 DCHECK_EQ(kFrameComplete, status_); 133 DCHECK_EQ(kFrameComplete, status_);
125 bitmap_.setImmutable(); 134 bitmap_.setImmutable();
126 return SkImage::MakeFromBitmap(bitmap_); 135 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, 211 // 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 212 // so we can't tell skia we're opaque, even for image types that logically
204 // always are (e.g. jpeg). 213 // always are (e.g. jpeg).
205 if (!has_alpha_ && status_ == kFrameComplete) 214 if (!has_alpha_ && status_ == kFrameComplete)
206 return kOpaque_SkAlphaType; 215 return kOpaque_SkAlphaType;
207 216
208 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 217 return premultiply_alpha_ ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
209 } 218 }
210 219
211 } // namespace blink 220 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698