Home | History | Annotate | Download | only in sk_app
      1 /*
      2  * Copyright 2016 Google Inc.
      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 #ifndef WindowContext_DEFINED
      8 #define WindowContext_DEFINED
      9 
     10 #include "DisplayParams.h"
     11 #include "GrTypes.h"
     12 #include "SkRefCnt.h"
     13 #include "SkSurfaceProps.h"
     14 
     15 class GrContext;
     16 class SkSurface;
     17 class GrRenderTarget;
     18 
     19 namespace sk_app {
     20 
     21 class WindowContext {
     22 public:
     23     WindowContext(const DisplayParams& params)
     24         : fContext(nullptr)
     25         , fDisplayParams(params)
     26         , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
     27         , fSampleCount(0)
     28         , fStencilBits(0) {}
     29 
     30     virtual ~WindowContext() {}
     31 
     32     virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
     33 
     34     virtual void swapBuffers() = 0;
     35 
     36     virtual bool isValid() = 0;
     37 
     38     virtual void resize(int w, int h) = 0;
     39 
     40     const DisplayParams& getDisplayParams() { return fDisplayParams; }
     41     virtual void setDisplayParams(const DisplayParams& params) = 0;
     42 
     43     SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
     44     void setSurfaceProps(const SkSurfaceProps& props) {
     45         fSurfaceProps = props;
     46     }
     47 
     48     virtual GrBackendContext getBackendContext() = 0;
     49     GrContext* getGrContext() const { return fContext; }
     50 
     51     int width() const { return fWidth; }
     52     int height() const { return fHeight; }
     53     int sampleCount() const { return fSampleCount; }
     54     int stencilBits() const { return fStencilBits; }
     55 
     56 protected:
     57     virtual bool isGpuContext() { return true;  }
     58 
     59     GrContext*        fContext;
     60 
     61     int               fWidth;
     62     int               fHeight;
     63     DisplayParams     fDisplayParams;
     64     GrPixelConfig     fPixelConfig;
     65     SkSurfaceProps    fSurfaceProps;
     66 
     67     // parameters obtained from the native window
     68     // Note that the platform .cpp file is responsible for
     69     // initializing fSampleCount and fStencilBits!
     70     int               fSampleCount;
     71     int               fStencilBits;
     72 };
     73 
     74 }   // namespace sk_app
     75 
     76 #endif
     77