| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 m_hasAlpha = other.m_hasAlpha; | 91 m_hasAlpha = other.m_hasAlpha; |
| 92 m_bitmap.reset(); | 92 m_bitmap.reset(); |
| 93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ImageFrame::setSize(int newWidth, int newHeight) | 96 bool ImageFrame::setSize(int newWidth, int newHeight) |
| 97 { | 97 { |
| 98 // setSize() should only be called once, it leaks memory otherwise. | 98 // setSize() should only be called once, it leaks memory otherwise. |
| 99 ASSERT(!width() && !height()); | 99 ASSERT(!width() && !height()); |
| 100 | 100 |
| 101 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | 101 m_bitmap.setInfo(SkImageInfo::MakeN32(newWidth, newHeight, |
| 102 m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType)); |
| 102 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 103 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
| 103 return false; | 104 return false; |
| 104 | 105 |
| 105 zeroFillPixelData(); | 106 zeroFillPixelData(); |
| 106 return true; | 107 return true; |
| 107 } | 108 } |
| 108 | 109 |
| 109 const SkBitmap& ImageFrame::bitmap() const | 110 const SkBitmap& ImageFrame::bitmap() const |
| 110 { | 111 { |
| 111 return m_bitmap; | 112 return m_bitmap; |
| 112 } | 113 } |
| 113 | 114 |
| 114 bool ImageFrame::hasAlpha() const | 115 bool ImageFrame::hasAlpha() const |
| 115 { | 116 { |
| 116 return m_hasAlpha; | 117 return m_hasAlpha; |
| 117 } | 118 } |
| 118 | 119 |
| 119 void ImageFrame::setHasAlpha(bool alpha) | 120 void ImageFrame::setHasAlpha(bool alpha) |
| 120 { | 121 { |
| 121 m_hasAlpha = alpha; | 122 m_hasAlpha = alpha; |
| 122 | 123 |
| 123 // If the frame is not fully loaded, there will be transparent pixels, | 124 m_bitmap.setAlphaType(computeAlphaType()); |
| 124 // so we can't tell skia we're opaque, even for image types that logically | |
| 125 // always are (e.g. jpeg). | |
| 126 if (m_status != FrameComplete) | |
| 127 alpha = true; | |
| 128 m_bitmap.setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType); | |
| 129 } | 125 } |
| 130 | 126 |
| 131 void ImageFrame::setStatus(Status status) | 127 void ImageFrame::setStatus(Status status) |
| 132 { | 128 { |
| 133 m_status = status; | 129 m_status = status; |
| 134 if (m_status == FrameComplete) { | 130 if (m_status == FrameComplete) { |
| 135 m_bitmap.setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlpha
Type); | 131 m_bitmap.setAlphaType(computeAlphaType()); |
| 136 // Send pending pixels changed notifications now, because we can't do th
is after | 132 // Send pending pixels changed notifications now, because we can't do th
is after |
| 137 // the bitmap has been marked immutable. | 133 // the bitmap has been marked immutable. |
| 138 notifyBitmapIfPixelsChanged(); | 134 notifyBitmapIfPixelsChanged(); |
| 139 m_bitmap.setImmutable(); // Tell the bitmap it's done. | 135 m_bitmap.setImmutable(); // Tell the bitmap it's done. |
| 140 } | 136 } |
| 141 } | 137 } |
| 142 | 138 |
| 143 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 139 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
| 144 { | 140 { |
| 145 if (rect.isEmpty()) | 141 if (rect.isEmpty()) |
| 146 return; | 142 return; |
| 147 | 143 |
| 148 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 144 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
| 149 setHasAlpha(true); | 145 setHasAlpha(true); |
| 150 } | 146 } |
| 151 | 147 |
| 148 SkAlphaType ImageFrame::computeAlphaType() const |
| 149 { |
| 150 // If the frame is not fully loaded, there will be transparent pixels, |
| 151 // so we can't tell skia we're opaque, even for image types that logically |
| 152 // always are (e.g. jpeg). |
| 153 if (!m_hasAlpha && m_status == FrameComplete) |
| 154 return kOpaque_SkAlphaType; |
| 155 |
| 156 return m_premultiplyAlpha ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; |
| 157 } |
| 158 |
| 152 } // namespace blink | 159 } // namespace blink |
| OLD | NEW |