Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / image-decoders / ImageFrame.cpp
blob3b75b8c146cb4f2e29ea3f220fac0f9797a9cdfd
1 /*
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "config.h"
28 #include "platform/image-decoders/ImageDecoder.h"
30 namespace blink {
32 ImageFrame::ImageFrame()
33 : m_allocator(0)
34 , m_hasAlpha(true)
35 , m_status(FrameEmpty)
36 , m_duration(0)
37 , m_disposalMethod(DisposeNotSpecified)
38 , m_alphaBlendSource(BlendAtopPreviousFrame)
39 , m_premultiplyAlpha(true)
40 , m_pixelsChanged(false)
41 , m_requiredPreviousFrameIndex(kNotFound)
45 ImageFrame& ImageFrame::operator=(const ImageFrame& other)
47 if (this == &other)
48 return *this;
50 m_bitmap = other.m_bitmap;
51 // Keep the pixels locked since we will be writing directly into the
52 // bitmap throughout this object's lifetime.
53 m_bitmap.lockPixels();
54 // Be sure to assign this before calling setStatus(), since setStatus() may
55 // call notifyBitmapIfPixelsChanged().
56 m_pixelsChanged = other.m_pixelsChanged;
57 setMemoryAllocator(other.allocator());
58 setOriginalFrameRect(other.originalFrameRect());
59 setStatus(other.status());
60 setDuration(other.duration());
61 setDisposalMethod(other.disposalMethod());
62 setAlphaBlendSource(other.alphaBlendSource());
63 setPremultiplyAlpha(other.premultiplyAlpha());
64 // Be sure that this is called after we've called setStatus(), since we
65 // look at our status to know what to do with the alpha value.
66 setHasAlpha(other.hasAlpha());
67 setRequiredPreviousFrameIndex(other.requiredPreviousFrameIndex());
68 return *this;
71 void ImageFrame::clearPixelData()
73 m_bitmap.reset();
74 m_status = FrameEmpty;
75 // NOTE: Do not reset other members here; clearFrameBufferCache()
76 // calls this to free the bitmap data, but other functions like
77 // initFrameBuffer() and frameComplete() may still need to read
78 // other metadata out of this frame later.
81 void ImageFrame::zeroFillPixelData()
83 m_bitmap.eraseARGB(0, 0, 0, 0);
84 m_hasAlpha = true;
87 bool ImageFrame::copyBitmapData(const ImageFrame& other)
89 if (this == &other)
90 return true;
92 m_hasAlpha = other.m_hasAlpha;
93 m_bitmap.reset();
94 return other.m_bitmap.copyTo(&m_bitmap, other.m_bitmap.colorType());
97 bool ImageFrame::setSize(int newWidth, int newHeight)
99 // setSize() should only be called once, it leaks memory otherwise.
100 ASSERT(!width() && !height());
102 m_bitmap.setInfo(SkImageInfo::MakeN32Premul(newWidth, newHeight));
103 if (!m_bitmap.tryAllocPixels(m_allocator, 0))
104 return false;
106 zeroFillPixelData();
107 return true;
110 const SkBitmap& ImageFrame::bitmap() const
112 return m_bitmap;
115 bool ImageFrame::hasAlpha() const
117 return m_hasAlpha;
120 void ImageFrame::setHasAlpha(bool alpha)
122 m_hasAlpha = alpha;
124 // If the frame is not fully loaded, there will be transparent pixels,
125 // so we can't tell skia we're opaque, even for image types that logically
126 // always are (e.g. jpeg).
127 if (m_status != FrameComplete)
128 alpha = true;
129 m_bitmap.setAlphaType(alpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
132 void ImageFrame::setStatus(Status status)
134 m_status = status;
135 if (m_status == FrameComplete) {
136 m_bitmap.setAlphaType(m_hasAlpha ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
137 // Send pending pixels changed notifications now, because we can't do this after
138 // the bitmap has been marked immutable.
139 notifyBitmapIfPixelsChanged();
140 m_bitmap.setImmutable(); // Tell the bitmap it's done.
144 void ImageFrame::zeroFillFrameRect(const IntRect& rect)
146 if (rect.isEmpty())
147 return;
149 m_bitmap.eraseArea(rect, SkColorSetARGB(0, 0, 0, 0));
150 setHasAlpha(true);
153 } // namespace blink