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() : fContext(nullptr)
     24                     , fSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType)
     25                     , fSampleCount(0)
     26                     , fStencilBits(0) {}
     27 
     28     virtual ~WindowContext() {}
     29 
     30     virtual sk_sp<SkSurface> getBackbufferSurface() = 0;
     31 
     32     virtual void swapBuffers() = 0;
     33 
     34     virtual bool isValid() = 0;
     35 
     36     virtual void resize(int w, int h) = 0;
     37 
     38     const DisplayParams& getDisplayParams() { return fDisplayParams; }
     39     virtual void setDisplayParams(const DisplayParams& params) = 0;
     40 
     41     SkSurfaceProps getSurfaceProps() const { return fSurfaceProps; }
     42     void setSurfaceProps(const SkSurfaceProps& props) {
     43         fSurfaceProps = props;
     44     }
     45 
     46     virtual GrBackendContext getBackendContext() = 0;
     47     GrContext* getGrContext() const { return fContext; }
     48 
     49     int width() const { return fWidth; }
     50     int height() const { return fHeight; }
     51     int sampleCount() const { return fSampleCount; }
     52     int stencilBits() const { return fStencilBits; }
     53 
     54 protected:
     55     virtual bool isGpuContext() { return true;  }
     56 
     57     GrContext*        fContext;
     58 
     59     int               fWidth;
     60     int               fHeight;
     61     DisplayParams     fDisplayParams;
     62     GrPixelConfig     fPixelConfig;
     63     SkSurfaceProps    fSurfaceProps;
     64 
     65     // parameters obtained from the native window
     66     // Note that the platform .cpp file is responsible for
     67     // initializing fSampleCount and fStencilBits!
     68     int               fSampleCount;
     69     int               fStencilBits;
     70 };
     71 
     72 }   // namespace sk_app
     73 
     74 #endif
     75