SkWindow.h revision da7b843fbd263e3421eef27c833206024dae8528
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkWindow_DEFINED
9#define SkWindow_DEFINED
10
11#include "SkView.h"
12#include "SkBitmap.h"
13#include "SkMatrix.h"
14#include "SkRegion.h"
15#include "SkEvent.h"
16#include "SkKey.h"
17#include "SkSurfaceProps.h"
18#include "SkTDArray.h"
19
20#ifdef SK_BUILD_FOR_WINCEx
21    #define SHOW_FPS
22#endif
23//#define USE_GX_SCREEN
24
25class SkSurface;
26class SkOSMenu;
27
28#if SK_SUPPORT_GPU
29struct GrGLInterface;
30class GrContext;
31class GrRenderTarget;
32#endif
33
34class SkWindow : public SkView {
35public:
36            SkWindow();
37    virtual ~SkWindow();
38
39    struct AttachmentInfo {
40        int fSampleCount;
41        int fStencilBits;
42    };
43
44    SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
45    void setSurfaceProps(const SkSurfaceProps& props) {
46        fSurfaceProps = props;
47    }
48
49    const SkBitmap& getBitmap() const { return fBitmap; }
50
51    void    setColorType(SkColorType);
52    void    resize(int width, int height, SkColorType = kUnknown_SkColorType);
53
54    bool    isDirty() const { return !fDirtyRgn.isEmpty(); }
55    bool    update(SkIRect* updateArea);
56    // does not call through to onHandleInval(), but does force the fDirtyRgn
57    // to be wide open. Call before update() to ensure we redraw everything.
58    void    forceInvalAll();
59    // return the bounds of the dirty/inval rgn, or [0,0,0,0] if none
60    const SkIRect& getDirtyBounds() const { return fDirtyRgn.getBounds(); }
61
62    bool    handleClick(int x, int y, Click::State, void* owner, unsigned modi = 0);
63    bool    handleChar(SkUnichar);
64    bool    handleKey(SkKey);
65    bool    handleKeyUp(SkKey);
66
67    void    addMenu(SkOSMenu*);
68    const SkTDArray<SkOSMenu*>* getMenus() { return &fMenus; }
69
70    const char* getTitle() const { return fTitle.c_str(); }
71    void    setTitle(const char title[]);
72
73    const SkMatrix& getMatrix() const { return fMatrix; }
74    void    setMatrix(const SkMatrix&);
75    void    preConcat(const SkMatrix&);
76    void    postConcat(const SkMatrix&);
77
78    virtual SkSurface* createSurface();
79
80    virtual void onPDFSaved(const char title[], const char desc[],
81        const char path[]) {}
82
83    virtual void setFullscreen(bool) {}
84    virtual void setVsync(bool) {}
85
86protected:
87    virtual bool onEvent(const SkEvent&);
88    virtual bool onDispatchClick(int x, int y, Click::State, void* owner, unsigned modi);
89    // called if part of our bitmap is invalidated
90    virtual void onHandleInval(const SkIRect&);
91    virtual bool onHandleChar(SkUnichar);
92    virtual bool onHandleKey(SkKey);
93    virtual bool onHandleKeyUp(SkKey);
94    virtual void onAddMenu(const SkOSMenu*) {};
95    virtual void onUpdateMenu(const SkOSMenu*) {};
96    virtual void onSetTitle(const char title[]) {}
97
98    // overrides from SkView
99    virtual bool handleInval(const SkRect*);
100    virtual bool onGetFocusView(SkView** focus) const;
101    virtual bool onSetFocusView(SkView* focus);
102
103#if SK_SUPPORT_GPU
104    GrRenderTarget* renderTarget(const AttachmentInfo& attachmentInfo,
105                                 const GrGLInterface* , GrContext* grContext);
106#endif
107
108private:
109    SkSurfaceProps  fSurfaceProps;
110    SkColorType fColorType;
111    SkBitmap    fBitmap;
112    SkRegion    fDirtyRgn;
113
114    SkTDArray<Click*>       fClicks; // to track clicks
115
116    SkTDArray<SkOSMenu*>    fMenus;
117
118    SkView* fFocusView;
119    bool    fWaitingOnInval;
120
121    SkString    fTitle;
122    SkMatrix    fMatrix;
123
124    typedef SkView INHERITED;
125};
126
127////////////////////////////////////////////////////////////////////////////////
128
129#if defined(SK_BUILD_FOR_MAC)
130    #include "SkOSWindow_Mac.h"
131#elif defined(SK_BUILD_FOR_WIN)
132    #include "SkOSWindow_Win.h"
133#elif defined(SK_BUILD_FOR_ANDROID)
134    #include "SkOSWindow_Android.h"
135#elif defined(SK_BUILD_FOR_UNIX)
136  #include "SkOSWindow_Unix.h"
137#elif defined(SK_BUILD_FOR_SDL)
138    #include "SkOSWindow_SDL.h"
139#elif defined(SK_BUILD_FOR_IOS)
140    #include "SkOSWindow_iOS.h"
141#endif
142
143#endif
144