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