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 28 matching lines...) Expand all Loading... | |
39 , m_premultiplyAlpha(true) | 39 , m_premultiplyAlpha(true) |
40 , m_pixelsChanged(false) | 40 , m_pixelsChanged(false) |
41 , m_requiredPreviousFrameIndex(kNotFound) | 41 , m_requiredPreviousFrameIndex(kNotFound) |
42 { | 42 { |
43 } | 43 } |
44 | 44 |
45 ImageFrame& ImageFrame::operator=(const ImageFrame& other) | 45 ImageFrame& ImageFrame::operator=(const ImageFrame& other) |
46 { | 46 { |
47 if (this == &other) | 47 if (this == &other) |
48 return *this; | 48 return *this; |
49 | |
50 m_bitmap = other.m_bitmap; | 49 m_bitmap = other.m_bitmap; |
51 // Keep the pixels locked since we will be writing directly into the | 50 // Keep the pixels locked since we will be writing directly into the |
52 // bitmap throughout this object's lifetime. | 51 // bitmap throughout this object's lifetime. |
53 m_bitmap.lockPixels(); | 52 m_bitmap.lockPixels(); |
54 // Be sure to assign this before calling setStatus(), since setStatus() may | 53 // Be sure to assign this before calling setStatus(), since setStatus() may |
55 // call notifyBitmapIfPixelsChanged(). | 54 // call notifyBitmapIfPixelsChanged(). |
56 m_pixelsChanged = other.m_pixelsChanged; | 55 m_pixelsChanged = other.m_pixelsChanged; |
57 setMemoryAllocator(other.allocator()); | 56 setMemoryAllocator(other.allocator()); |
58 setOriginalFrameRect(other.originalFrameRect()); | 57 setOriginalFrameRect(other.originalFrameRect()); |
59 setStatus(other.status()); | 58 setStatus(other.status()); |
(...skipping 27 matching lines...) Expand all Loading... | |
87 bool ImageFrame::copyBitmapData(const ImageFrame& other) | 86 bool ImageFrame::copyBitmapData(const ImageFrame& other) |
88 { | 87 { |
89 if (this == &other) | 88 if (this == &other) |
90 return true; | 89 return true; |
91 | 90 |
92 m_hasAlpha = other.m_hasAlpha; | 91 m_hasAlpha = other.m_hasAlpha; |
93 m_bitmap.reset(); | 92 m_bitmap.reset(); |
94 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); | 93 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType()); |
95 } | 94 } |
96 | 95 |
97 bool ImageFrame::setSize(int newWidth, int newHeight) | 96 bool ImageFrame::setSize(int newWidth, int newHeight, ColorType bitmapType) |
98 { | 97 { |
99 // setSize() should only be called once, it leaks memory otherwise. | 98 // shouldn't be called with the same size, though not a problem if it happen s |
100 ASSERT(!width() && !height()); | 99 ASSERT(m_bitmap.isNull() || hasSize(IntSize(newWidth, newHeight), bitmapType )); |
100 if (bitmapType == RGBA8888) { | |
101 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | |
102 } else if (bitmapType == RGB565) { | |
103 m_bitmap.setInfo(SkImageInfo::Make(newWidth, newHeight, kRGB_565_SkColor Type, kOpaque_SkAlphaType)); | |
104 } else { | |
105 ASSERT(false); | |
106 } | |
101 | 107 |
102 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight)); | |
103 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) | 108 if (!m_bitmap.tryAllocPixels(m_allocator, 0)) |
104 return false; | 109 return false; |
105 | 110 |
106 zeroFillPixelData(); | 111 zeroFillPixelData(); |
scroggo_chromium
2015/10/28 19:08:47
This will erase the background to black, in the ca
aleksandar.stojiljkovic
2015/10/29 13:06:42
The initial idea was to let image generators decod
| |
107 return true; | 112 return true; |
108 } | 113 } |
109 | 114 |
110 const SkBitmap& ImageFrame::bitmap() const | 115 const SkBitmap& ImageFrame::bitmap() const |
111 { | 116 { |
112 return m_bitmap; | 117 return m_bitmap; |
113 } | 118 } |
114 | 119 |
115 bool ImageFrame::hasAlpha() const | 120 bool ImageFrame::hasAlpha() const |
116 { | 121 { |
(...skipping 27 matching lines...) Expand all Loading... | |
144 void ImageFrame::zeroFillFrameRect(const IntRect& rect) | 149 void ImageFrame::zeroFillFrameRect(const IntRect& rect) |
145 { | 150 { |
146 if (rect.isEmpty()) | 151 if (rect.isEmpty()) |
147 return; | 152 return; |
148 | 153 |
149 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); | 154 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0)); |
150 setHasAlpha(true); | 155 setHasAlpha(true); |
151 } | 156 } |
152 | 157 |
153 } // namespace blink | 158 } // namespace blink |
OLD | NEW |