15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
27757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch * Copyright (C) 2013 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1.  Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2.  Redistributions in binary form must reproduce the above copyright
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     notice, this list of conditions and the following disclaimer in the
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *     documentation and/or other materials provided with the distribution.
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#ifndef DecodingImageGenerator_h
2709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#define DecodingImageGenerator_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "SkImageGenerator.h"
3009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "SkImageInfo.h"
3109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "wtf/RefPtr.h"
3309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)class SkData;
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore {
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
3809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)class ImageFrameGenerator;
3909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// Implements SkImageGenerator and used by SkPixelRef to populate a discardable
4109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// memory with decoded pixels.
4209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)//
4309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// This class does not own an ImageDecode. It does not own encoded data. It serves
4409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)// as and adapter to ImageFrameGenerator which actually performs decoding.
4509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)class DecodingImageGenerator FINAL : public SkImageGenerator {
4609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)public:
4709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    DecodingImageGenerator(PassRefPtr<ImageFrameGenerator>, const SkImageInfo&, size_t index);
4809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    virtual ~DecodingImageGenerator();
495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    void setGenerationId(size_t id) { m_generationId = id; }
5109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
52f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)protected:
53f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    virtual SkData* onRefEncodedData() OVERRIDE;
54f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    virtual bool onGetInfo(SkImageInfo*) OVERRIDE;
55f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)    virtual bool onGetPixels(const SkImageInfo&, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) OVERRIDE;
56f6b7aed3f7ce69aca0d7a032d144cbd088b04393Torne (Richard Coles)
5709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)private:
5809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    RefPtr<ImageFrameGenerator> m_frameGenerator;
5909380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    SkImageInfo m_imageInfo;
6009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    size_t m_frameIndex;
6109380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    size_t m_generationId;
6209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)};
635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore
6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#endif // DecodingImageGenerator_h_
67