1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
28a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/*
3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2008 The Android Open Source Project
48a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com *
5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be
6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file.
78a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
88a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
9ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com
108a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#ifndef SkPageFlipper_DEFINED
118a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#define SkPageFlipper_DEFINED
128a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
138a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#include "SkRegion.h"
148a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
158a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com/** SkPageFlipper manages alternating inval/dirty regions for a rectangular area
168a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    (like a bitmap). You call inval() to accumulate inval areas, and then when
178a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    you're ready to "flip" pages (i.e. draw into the one you've been
188a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    invalidating) you call update, which swaps the inval regions, and returns
198a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    two things to you: 1) the final inval region to be drawn into, and 2) the
208a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    region of pixels that should be copied from the "front" page onto the one
218a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    you're about to draw into. This copyBits region will be disjoint from the
228a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    inval region, so both need to be handled.
238a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com */
248a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comclass SkPageFlipper {
258a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.compublic:
268a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPageFlipper();
278a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkPageFlipper(int width, int height);
28fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
298a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int width() const { return fWidth; }
308a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int height() const { return fHeight; }
318a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
328a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void resize(int width, int height);
338a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
348a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    bool isDirty() const { return !fDirty1->isEmpty(); }
358a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkRegion& dirtyRgn() const { return *fDirty1; }
368a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
378a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void inval();
388a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void inval(const SkIRect&);
398a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void inval(const SkRegion&);
408a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    void inval(const SkRect&, bool antialias);
418a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
428a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    /** When you're ready to write to the back page, call update. The returned
438a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        region is the invalidate are that needs to be drawn to. The copyBits
448a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        region (provided by the caller) is the area that should be copied from
458a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        the front page to the back page (will not intersect with the returned
468a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        inval region.
47fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com
488a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        Once this is called, the two internal regions are swapped, so the *new*
498a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com        back inval region is ready to receive new inval calls.
508a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com     */
518a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    const SkRegion& update(SkRegion* copyBits);
528a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
538a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.comprivate:
548a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRegion*   fDirty0;
558a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRegion*   fDirty1;
568a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRegion    fDirty0Storage;
578a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    SkRegion    fDirty1Storage;
588a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fWidth;
598a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com    int         fHeight;
608a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com};
618a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com
628a1c16ff38322f0210116fa7293eb8817c7e477ereed@android.com#endif
63