Chromium Code Reviews| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 89 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
| 90 { | 90 { |
| 91 if (this == &other) | 91 if (this == &other) |
| 92 return true; | 92 return true; |
| 93 | 93 |
| 94 m_hasAlpha = other.m_hasAlpha; | 94 m_hasAlpha = other.m_hasAlpha; |
| 95 m_bitmap.reset(); | 95 m_bitmap.reset(); |
| 96 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 96 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool ImageFrame::takeBitmapDataIfWritable(ImageFrame* other) | |
| 100 { | |
| 101 DCHECK(other); | |
| 102 if (this == other) | |
| 103 return false; | |
| 104 if (other->m_bitmap.isImmutable()) | |
|
Peter Kasting
2016/08/26 19:04:04
Nit: Just combine these conditionals
aleksandar.stojiljkovic
2016/08/26 21:53:51
Done.
| |
| 105 return false; | |
| 106 m_hasAlpha = other->m_hasAlpha; | |
| 107 m_bitmap.reset(); | |
| 108 m_bitmap.swap(other->m_bitmap); | |
| 109 other->m_status = FrameEmpty; | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 99 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile) | 113 bool ImageFrame::setSizeAndColorProfile(int newWidth, int newHeight, const ICCPr ofile& newIccProfile) |
| 100 { | 114 { |
| 101 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise. | 115 // setSizeAndColorProfile() should only be called once, it leaks memory othe rwise. |
| 102 ASSERT(!width() && !height()); | 116 ASSERT(!width() && !height()); |
| 103 | 117 |
| 104 sk_sp<SkColorSpace> colorSpace; | 118 sk_sp<SkColorSpace> colorSpace; |
| 105 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled() && !newIccProfile .isEmpty()) | 119 if (RuntimeEnabledFeatures::colorCorrectRenderingEnabled() && !newIccProfile .isEmpty()) |
| 106 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfile.si ze()); | 120 colorSpace = SkColorSpace::NewICC(newIccProfile.data(), newIccProfile.si ze()); |
| 107 | 121 |
| 108 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, | 122 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, |
| 109 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); | 123 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType, colorS pace)); |
| 110 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 124 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
| 111 return false; | 125 return false; |
| 112 | 126 |
| 113 zeroFillPixelData(); | 127 zeroFillPixelData(); |
| 114 return true; | 128 return true; |
| 115 } | 129 } |
| 116 | 130 |
| 117 bool ImageFrame::hasAlpha() const | 131 bool ImageFrame::hasAlpha() const |
| 118 { | 132 { |
| 119 return m_hasAlpha; | 133 return m_hasAlpha; |
| 120 } | 134 } |
| 121 | 135 |
| 136 const SkBitmap& ImageFrame::bitmap(bool setImmutableIfDone) | |
|
aleksandar.stojiljkovic
2016/08/26 18:53:41
pkasting@
The fix for the failing tests is simpler
| |
| 137 { | |
| 138 if (m_status == FrameComplete && setImmutableIfDone && !m_bitmap.isImmutable ()) { | |
| 139 // We don't set the status to immutable until there is a request to | |
| 140 // access the bitmap. This is because mutable bitmap can be reused as | |
| 141 // the next frame by calling takeBitmapDataIfWritable. | |
| 142 m_bitmap.setImmutable(); | |
| 143 } | |
| 144 return m_bitmap; | |
| 145 } | |
| 146 | |
| 122 void ImageFrame::setHasAlpha(bool alpha) | 147 void ImageFrame::setHasAlpha(bool alpha) |
| 123 { | 148 { |
| 124 m_hasAlpha = alpha; | 149 m_hasAlpha = alpha; |
| 125 | 150 |
| 126 m_bitmap.setAlphaType(computeAlphaType()); | 151 m_bitmap.setAlphaType(computeAlphaType()); |
| 127 } | 152 } |
| 128 | 153 |
| 129 void ImageFrame::setStatus(Status status) | 154 void ImageFrame::setStatus(Status status) |
| 130 { | 155 { |
| 131 m_status = status; | 156 m_status = status; |
| 132 if (m_status == FrameComplete) { | 157 if (m_status == FrameComplete) { |
| 133 m_bitmap.setAlphaType(computeAlphaType()); | 158 m_bitmap.setAlphaType(computeAlphaType()); |
| 134 // Send pending pixels changed notifications now, because we can't do th is after | 159 // Send pending pixels changed notifications now, because we can't do th is after |
| 135 // the bitmap has been marked immutable. | 160 // the bitmap has been marked immutable. |
| 136 notifyBitmapIfPixelsChanged(); | 161 notifyBitmapIfPixelsChanged(); |
| 137 m_bitmap.setImmutable(); // Tell the bitmap it's done. | |
| 138 } | 162 } |
| 139 } | 163 } |
| 140 | 164 |
| 141 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 165 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
| 142 { | 166 { |
| 143 if (rect.isEmpty()) | 167 if (rect.isEmpty()) |
| 144 return; | 168 return; |
| 145 | 169 |
| 146 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 170 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
| 147 setHasAlpha(true); | 171 setHasAlpha(true); |
| 148 } | 172 } |
| 149 | 173 |
| 150 SkAlphaType ImageFrame::computeAlphaType() const | 174 SkAlphaType ImageFrame::computeAlphaType() const |
| 151 { | 175 { |
| 152 // If the frame is not fully loaded, there will be transparent pixels, | 176 // If the frame is not fully loaded, there will be transparent pixels, |
| 153 // so we can't tell skia we're opaque, even for image types that logically | 177 // so we can't tell skia we're opaque, even for image types that logically |
| 154 // always are (e.g. jpeg). | 178 // always are (e.g. jpeg). |
| 155 if (!m_hasAlpha && m_status == FrameComplete) | 179 if (!m_hasAlpha && m_status == FrameComplete) |
| 156 return kOpaque_SkAlphaType; | 180 return kOpaque_SkAlphaType; |
| 157 | 181 |
| 158 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; | 182 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
| 159 } | 183 } |
| 160 | 184 |
| 161 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |