 Chromium Code Reviews
 Chromium Code Reviews Issue 2749703002:
  Refactor ImageFrame::setSizeAndColorSpace()  (Closed)
    
  
    Issue 2749703002:
  Refactor ImageFrame::setSizeAndColorSpace()  (Closed) 
  | OLD | NEW | 
|---|---|
| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 void ImageFrame::clearPixelData() { | 71 void ImageFrame::clearPixelData() { | 
| 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 setHasAlpha(true); | |
| 
Noel Gordon
2017/03/16 12:01:50
Harmless, but also redundant.  It sets the m_bitma
 
cblume
2017/03/17 05:35:14
Wait....you're right.
I could have sworn it made p
 
Peter Kasting
2017/03/17 06:35:50
Because the BMP decoder needs it, no?
It allocate
 
cblume
2017/03/17 18:05:45
It is now being explicitly set in BMPImageReader.c
 
Noel Gordon
2017/03/20 13:24:52
Not sure they're separate concepts.  Somewhat odd
 | |
| 81 m_bitmap.eraseARGB(0, 0, 0, 0); | 82 m_bitmap.eraseARGB(0, 0, 0, 0); | 
| 82 m_hasAlpha = true; | |
| 83 } | 83 } | 
| 84 | 84 | 
| 85 bool ImageFrame::copyBitmapData(const ImageFrame& other) { | 85 bool ImageFrame::copyBitmapData(const ImageFrame& other) { | 
| 86 DCHECK_NE(this, &other); | 86 DCHECK_NE(this, &other); | 
| 87 m_hasAlpha = other.m_hasAlpha; | 87 m_hasAlpha = other.m_hasAlpha; | 
| 88 m_bitmap.reset(); | 88 m_bitmap.reset(); | 
| 89 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 89 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 
| 90 } | 90 } | 
| 91 | 91 | 
| 92 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) { | 92 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) { | 
| 93 DCHECK(other); | 93 DCHECK(other); | 
| 94 DCHECK_EQ(FrameComplete, other->m_status); | 94 DCHECK_EQ(FrameComplete, other->m_status); | 
| 95 DCHECK_EQ(FrameEmpty, m_status); | 95 DCHECK_EQ(FrameEmpty, m_status); | 
| 96 DCHECK_NE(this, other); | 96 DCHECK_NE(this, other); | 
| 97 if (other->m_bitmap.isImmutable()) | 97 if (other->m_bitmap.isImmutable()) | 
| 98 return false; | 98 return false; | 
| 99 m_hasAlpha = other->m_hasAlpha; | 99 m_hasAlpha = other->m_hasAlpha; | 
| 100 m_bitmap.reset(); | 100 m_bitmap.reset(); | 
| 101 m_bitmap.swap(other->m_bitmap); | 101 m_bitmap.swap(other->m_bitmap); | 
| 102 other->m_status = FrameEmpty; | 102 other->m_status = FrameEmpty; | 
| 103 return true; | 103 return true; | 
| 104 } | 104 } | 
| 105 | 105 | 
| 106 bool ImageFrame::setSizeAndColorSpace(int newWidth, | 106 bool ImageFrame::allocatePixelData(int newWidth, | 
| 107 int newHeight, | 107 int newHeight, | 
| 108 sk_sp<SkColorSpace> colorSpace) { | 108 sk_sp<SkColorSpace> colorSpace) { | 
| 109 // setSizeAndColorSpace() should only be called once, it leaks memory | |
| 110 // otherwise. | |
| 111 DCHECK(!width() && !height()); | |
| 112 | |
| 113 m_bitmap.setInfo(SkImageInfo::MakeN32( | 109 m_bitmap.setInfo(SkImageInfo::MakeN32( | 
| 114 newWidth, newHeight, | 110 newWidth, newHeight, | 
| 115 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, | 111 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, | 
| 116 std::move(colorSpace))); | 112 std::move(colorSpace))); | 
| 117 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 113 return m_bitmap.tryAllocPixels(m_allocator, 0); | 
| 118 return false; | |
| 119 | |
| 120 zeroFillPixelData(); | |
| 121 return true; | |
| 122 } | 114 } | 
| 123 | 115 | 
| 124 bool ImageFrame::hasAlpha() const { | 116 bool ImageFrame::hasAlpha() const { | 
| 125 return m_hasAlpha; | 117 return m_hasAlpha; | 
| 126 } | 118 } | 
| 127 | 119 | 
| 128 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { | 120 sk_sp<SkImage> ImageFrame::finalizePixelsAndGetImage() { | 
| 129 DCHECK_EQ(FrameComplete, m_status); | 121 DCHECK_EQ(FrameComplete, m_status); | 
| 130 m_bitmap.setImmutable(); | 122 m_bitmap.setImmutable(); | 
| 131 return SkImage::MakeFromBitmap(m_bitmap); | 123 return SkImage::MakeFromBitmap(m_bitmap); | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 // If the frame is not fully loaded, there will be transparent pixels, | 199 // If the frame is not fully loaded, there will be transparent pixels, | 
| 208 // so we can't tell skia we're opaque, even for image types that logically | 200 // so we can't tell skia we're opaque, even for image types that logically | 
| 209 // always are (e.g. jpeg). | 201 // always are (e.g. jpeg). | 
| 210 if (!m_hasAlpha && m_status == FrameComplete) | 202 if (!m_hasAlpha && m_status == FrameComplete) | 
| 211 return kOpaque_SkAlphaType; | 203 return kOpaque_SkAlphaType; | 
| 212 | 204 | 
| 213 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 205 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 
| 214 } | 206 } | 
| 215 | 207 | 
| 216 } // namespace blink | 208 } // namespace blink | 
| OLD | NEW |