129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed/*
2a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44Duy Truong * Copyright (c) 2011, The Linux Foundation. All rights reserved.
329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * Redistribution and use in source and binary forms, with or without
529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * modification, are permitted provided that the following conditions are
629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * met:
729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *   * Redistributions of source code must retain the above copyright
829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     notice, this list of conditions and the following disclaimer.
929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *   * Redistributions in binary form must reproduce the above
1029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     copyright notice, this list of conditions and the following
1129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     disclaimer in the documentation and/or other materials provided
1229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     with the distribution.
13a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44Duy Truong *   * Neither the name of The Linux Foundation nor the names of its
1429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     contributors may be used to endorse or promote products derived
1529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *     from this software without specific prior written permission.
1629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed *
1729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
1829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
2029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
2129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
2429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
2529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
2629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
2729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed */
2929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
3029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed#include <copybit.h>
3129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct copybit_iterator : public copybit_region_t {
3229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    copybit_iterator(const copybit_rect_t& rect) {
3329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mRect = rect;
3429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        mCount = 1;
3529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        this->next = iterate;
3629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
3729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedprivate:
3829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    static int iterate(copybit_region_t const * self, copybit_rect_t* rect) {
3929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        if (!self || !rect) {
4029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return 0;
4129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        }
4229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
4329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        copybit_iterator const* me = static_cast<copybit_iterator const*>(self);
4429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        if (me->mCount) {
4529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            rect->l = me->mRect.l;
4629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            rect->t = me->mRect.t;
4729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            rect->r = me->mRect.r;
4829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            rect->b = me->mRect.b;
4929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            me->mCount--;
5029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed            return 1;
5129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        }
5229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        return 0;
5329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    }
5429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    copybit_rect_t mRect;
5529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    mutable int mCount;
5629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
57