1545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch/*
2545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * Copyright (C) 2010 Google Inc. All rights reserved.
3545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *
4545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * Redistribution and use in source and binary forms, with or without
5545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * modification, are permitted provided that the following conditions are
6545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * met:
7545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *
8545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *     * Redistributions of source code must retain the above copyright
9545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * notice, this list of conditions and the following disclaimer.
10545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *     * Redistributions in binary form must reproduce the above
11545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * copyright notice, this list of conditions and the following disclaimer
12545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * in the documentation and/or other materials provided with the
13545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * distribution.
14545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *     * Neither the name of Google Inc. nor the names of its
15545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * contributors may be used to endorse or promote products derived from
16545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * this software without specific prior written permission.
17545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch *
18545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch */
30545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
31545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "config.h"
32545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#if ENABLE(IMAGE_RESIZER)
33545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
34545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "AsyncImageResizer.h"
35545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
36545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "CachedImage.h"
37545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "ImageResizerThread.h"
38545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "SharedBuffer.h"
39545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include <utility>
40545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
41545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochnamespace WebCore {
42545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
43545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochPassRefPtr<AsyncImageResizer> AsyncImageResizer::create(CachedImage* cachedImage, OutputType outputType, IntSize desiredBounds, ScriptValue successCallback, ScriptValue errorCallback, float quality, AspectRatioOption aspectRatioOption, OrientationOption orientationOption)
44545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
45545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    return adoptRef(new AsyncImageResizer(cachedImage, outputType, desiredBounds, successCallback, errorCallback, quality, aspectRatioOption, orientationOption));
46545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
47545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
48545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochAsyncImageResizer::AsyncImageResizer(CachedImage* cachedImage, OutputType outputType, IntSize desiredBounds, ScriptValue successCallback, ScriptValue errorCallback, float quality, AspectRatioOption aspectRatioOption, OrientationOption orientationOption)
49545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    : m_cachedImage(cachedImage)
50545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_successCallback(successCallback)
51545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_errorCallback(errorCallback)
52545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_outputType(outputType)
53545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_desiredBounds(desiredBounds)
54545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_quality(quality)
55545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_aspectRatioOption(aspectRatioOption)
56545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    , m_orientationOption(orientationOption)
57545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
58545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    ASSERT(m_successCallback.isObject());
59545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    m_cachedImage->addClient(this);
60545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
61545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
62545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochAsyncImageResizer::~AsyncImageResizer()
63545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
64545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
65545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
66545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochvoid AsyncImageResizer::notifyFinished(CachedResource* cachedResource)
67545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
68545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    RefPtr<SharedBuffer> imageData = cachedResource->data()->copy();
69545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    cachedResource->removeClient(this);
70545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    CallbackInfo* callbackInfo = new CallbackInfo(this);
71545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    if (!ImageResizerThread::start(imageData, callbackInfo, m_outputType, m_desiredBounds, m_quality, m_aspectRatioOption, m_orientationOption))
72545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        resizeError();
73545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
74545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
75545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch} // namespace WebCore
76545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
77545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#endif // ENABLE(IMAGE_RESIZER)
78