~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/platform/graphics/chromium/ImageDecodingStore.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 Google Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
7
 * 1. Redistributions of source code must retain the above copyright
 
8
 *    notice, this list of conditions and the following disclaimer.
 
9
 * 2. Redistributions in binary form must reproduce the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer in the
 
11
 *    documentation and/or other materials provided with the distribution.
 
12
 *
 
13
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
24
 */
 
25
 
 
26
#ifndef ImageDecodingStore_h
 
27
#define ImageDecodingStore_h
 
28
 
 
29
#include "ScaledImageFragment.h"
 
30
#include "SkTypes.h"
 
31
#include "SkSize.h"
 
32
#include "SkSizeHash.h"
 
33
 
 
34
#include <wtf/OwnPtr.h>
 
35
#include <wtf/PassOwnPtr.h>
 
36
#include <wtf/ThreadingPrimitives.h>
 
37
#include <wtf/Vector.h>
 
38
 
 
39
namespace WebCore {
 
40
 
 
41
class ImageDecoder;
 
42
class ImageFrameGenerator;
 
43
class SharedBuffer;
 
44
 
 
45
class ImageDecodingStore {
 
46
public:
 
47
    static PassOwnPtr<ImageDecodingStore> create() { return adoptPtr(new ImageDecodingStore); }
 
48
    ~ImageDecodingStore();
 
49
 
 
50
    static ImageDecodingStore* instance();
 
51
    static void initializeOnce();
 
52
    static void shutdown();
 
53
 
 
54
    const ScaledImageFragment* lockCompleteCache(const ImageFrameGenerator*, const SkISize& scaledSize);
 
55
    const ScaledImageFragment* lockIncompleteCache(const ImageFrameGenerator*, const SkISize& scaledSize);
 
56
    void unlockCache(const ImageFrameGenerator*, const ScaledImageFragment*);
 
57
    const ScaledImageFragment* insertAndLockCache(const ImageFrameGenerator*, PassOwnPtr<ScaledImageFragment>);
 
58
 
 
59
private:
 
60
    struct CacheEntry {
 
61
        static PassOwnPtr<CacheEntry> create() { return adoptPtr(new CacheEntry()); }
 
62
        static PassOwnPtr<CacheEntry> createAndUse(PassOwnPtr<ScaledImageFragment> image) { return adoptPtr(new CacheEntry(image, 1)); }
 
63
 
 
64
        CacheEntry()
 
65
            : useCount(0)
 
66
        {
 
67
        }
 
68
 
 
69
        CacheEntry(PassOwnPtr<ScaledImageFragment> image, int count)
 
70
            : cachedImage(image)
 
71
            , useCount(count)
 
72
        {
 
73
        }
 
74
 
 
75
        ~CacheEntry()
 
76
        {
 
77
            ASSERT(!useCount);
 
78
        }
 
79
 
 
80
        OwnPtr<ScaledImageFragment> cachedImage;
 
81
        int useCount;
 
82
    };
 
83
 
 
84
    ImageDecodingStore();
 
85
    void prune();
 
86
 
 
87
    Vector<OwnPtr<CacheEntry> > m_cacheEntries;
 
88
 
 
89
    typedef std::pair<const ImageFrameGenerator*, SkISize> CacheIdentifier;
 
90
    typedef HashMap<CacheIdentifier, CacheEntry*> CacheMap;
 
91
    CacheMap m_cacheMap;
 
92
 
 
93
    // Protect concurrent access to all instances of CacheEntry stored in m_cacheEntries and
 
94
    // m_cacheMap as well as the containers.
 
95
    Mutex m_mutex;
 
96
};
 
97
 
 
98
} // namespace WebCore
 
99
 
 
100
#endif