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

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

Issue 2762643004: Separate zeroing pixel data from setting alpha (Closed)
Patch Set: Rebase Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/image-decoders/bmp/BMPImageReader.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 m_bitmap.reset(); 72 m_bitmap.reset();
73 m_status = FrameEmpty; 73 m_status = FrameEmpty;
74 // NOTE: Do not reset other members here; clearFrameBufferCache() 74 // NOTE: Do not reset other members here; clearFrameBufferCache()
75 // calls this to free the bitmap data, but other functions like 75 // calls this to free the bitmap data, but other functions like
76 // initFrameBuffer() and frameComplete() may still need to read 76 // initFrameBuffer() and frameComplete() may still need to read
77 // other metadata out of this frame later. 77 // other metadata out of this frame later.
78 } 78 }
79 79
80 void ImageFrame::zeroFillPixelData() { 80 void ImageFrame::zeroFillPixelData() {
81 m_bitmap.eraseARGB(0, 0, 0, 0); 81 m_bitmap.eraseARGB(0, 0, 0, 0);
82 m_hasAlpha = true;
83 } 82 }
84 83
85 bool ImageFrame::copyBitmapData(const ImageFrame& other) { 84 bool ImageFrame::copyBitmapData(const ImageFrame& other) {
86 DCHECK_NE(this, &other); 85 DCHECK_NE(this, &other);
87 m_hasAlpha = other.m_hasAlpha; 86 m_hasAlpha = other.m_hasAlpha;
88 m_bitmap.reset(); 87 m_bitmap.reset();
89 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); 88 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType());
90 } 89 }
91 90
92 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) { 91 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) {
93 DCHECK(other); 92 DCHECK(other);
94 DCHECK_EQ(FrameComplete, other->m_status); 93 DCHECK_EQ(FrameComplete, other->m_status);
95 DCHECK_EQ(FrameEmpty, m_status); 94 DCHECK_EQ(FrameEmpty, m_status);
96 DCHECK_NE(this, other); 95 DCHECK_NE(this, other);
97 if (other->m_bitmap.isImmutable()) 96 if (other->m_bitmap.isImmutable())
98 return false; 97 return false;
99 m_hasAlpha = other->m_hasAlpha; 98 m_hasAlpha = other->m_hasAlpha;
100 m_bitmap.reset(); 99 m_bitmap.reset();
101 m_bitmap.swap(other->m_bitmap); 100 m_bitmap.swap(other->m_bitmap);
102 other->m_status = FrameEmpty; 101 other->m_status = FrameEmpty;
103 return true; 102 return true;
104 } 103 }
105 104
106 bool ImageFrame::allocatePixelData(int newWidth, 105 bool ImageFrame::allocatePixelData(int newWidth,
107 int newHeight, 106 int newHeight,
108 sk_sp<SkColorSpace> colorSpace) { 107 sk_sp<SkColorSpace> colorSpace) {
109 // allocatePixelData() should only be called once. 108 // allocatePixelData() should only be called once.
110 DCHECK(!width() && !height()); 109 DCHECK(!width() && !height());
111 110
112 m_bitmap.setInfo(SkImageInfo::MakeN32( 111 SkAlphaType alphaType = kOpaque_SkAlphaType;
113 newWidth, newHeight, 112 if (m_hasAlpha) {
114 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, 113 alphaType =
115 std::move(colorSpace))); 114 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
115 }
116
117 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, alphaType,
118 std::move(colorSpace)));
116 return m_bitmap.tryAllocPixels(m_allocator, 0); 119 return m_bitmap.tryAllocPixels(m_allocator, 0);
117 } 120 }
118 121
119 bool ImageFrame::hasAlpha() const { 122 bool ImageFrame::hasAlpha() const {
120 return m_hasAlpha; 123 return m_hasAlpha;
121 } 124 }
122 125
123 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { 126 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() {
124 DCHECK_EQ(FrameComplete, m_status); 127 DCHECK_EQ(FrameComplete, m_status);
125 m_bitmap.setImmutable(); 128 m_bitmap.setImmutable();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 // If the frame is not fully loaded, there will be transparent pixels, 205 // 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 206 // so we can't tell skia we're opaque, even for image types that logically
204 // always are (e.g. jpeg). 207 // always are (e.g. jpeg).
205 if (!m_hasAlpha && m_status == FrameComplete) 208 if (!m_hasAlpha && m_status == FrameComplete)
206 return kOpaque_SkAlphaType; 209 return kOpaque_SkAlphaType;
207 210
208 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; 211 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
209 } 212 }
210 213
211 } // namespace blink 214 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/image-decoders/bmp/BMPImageReader.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698