1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2016 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#ifndef WindowContext_DEFINED 8cb93a386Sopenharmony_ci#define WindowContext_DEFINED 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 11cb93a386Sopenharmony_ci#include "include/core/SkSurfaceProps.h" 12cb93a386Sopenharmony_ci#include "include/gpu/GrTypes.h" 13cb93a386Sopenharmony_ci#include "tools/sk_app/DisplayParams.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ciclass GrDirectContext; 16cb93a386Sopenharmony_ciclass SkSurface; 17cb93a386Sopenharmony_ci#ifdef SK_GRAPHITE_ENABLED 18cb93a386Sopenharmony_cinamespace skgpu { 19cb93a386Sopenharmony_ciclass Context; 20cb93a386Sopenharmony_ci} 21cb93a386Sopenharmony_ci#endif 22cb93a386Sopenharmony_ci 23cb93a386Sopenharmony_cinamespace sk_app { 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_ciclass WindowContext { 26cb93a386Sopenharmony_cipublic: 27cb93a386Sopenharmony_ci WindowContext(const DisplayParams&); 28cb93a386Sopenharmony_ci 29cb93a386Sopenharmony_ci virtual ~WindowContext(); 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci virtual sk_sp<SkSurface> getBackbufferSurface() = 0; 32cb93a386Sopenharmony_ci 33cb93a386Sopenharmony_ci virtual void swapBuffers() = 0; 34cb93a386Sopenharmony_ci 35cb93a386Sopenharmony_ci virtual bool isValid() = 0; 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci virtual void resize(int w, int h) = 0; 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci virtual void activate(bool isActive) {} 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci const DisplayParams& getDisplayParams() { return fDisplayParams; } 42cb93a386Sopenharmony_ci virtual void setDisplayParams(const DisplayParams& params) = 0; 43cb93a386Sopenharmony_ci 44cb93a386Sopenharmony_ci GrDirectContext* directContext() const { return fContext.get(); } 45cb93a386Sopenharmony_ci#ifdef SK_GRAPHITE_ENABLED 46cb93a386Sopenharmony_ci skgpu::Context* graphiteContext() const { return fGraphiteContext.get(); } 47cb93a386Sopenharmony_ci#endif 48cb93a386Sopenharmony_ci 49cb93a386Sopenharmony_ci int width() const { return fWidth; } 50cb93a386Sopenharmony_ci int height() const { return fHeight; } 51cb93a386Sopenharmony_ci int sampleCount() const { return fSampleCount; } 52cb93a386Sopenharmony_ci int stencilBits() const { return fStencilBits; } 53cb93a386Sopenharmony_ci 54cb93a386Sopenharmony_ciprotected: 55cb93a386Sopenharmony_ci virtual bool isGpuContext() { return true; } 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_ci sk_sp<GrDirectContext> fContext; 58cb93a386Sopenharmony_ci#if SK_GRAPHITE_ENABLED 59cb93a386Sopenharmony_ci sk_sp<skgpu::Context> fGraphiteContext; 60cb93a386Sopenharmony_ci#endif 61cb93a386Sopenharmony_ci 62cb93a386Sopenharmony_ci int fWidth; 63cb93a386Sopenharmony_ci int fHeight; 64cb93a386Sopenharmony_ci DisplayParams fDisplayParams; 65cb93a386Sopenharmony_ci 66cb93a386Sopenharmony_ci // parameters obtained from the native window 67cb93a386Sopenharmony_ci // Note that the platform .cpp file is responsible for 68cb93a386Sopenharmony_ci // initializing fSampleCount and fStencilBits! 69cb93a386Sopenharmony_ci int fSampleCount = 1; 70cb93a386Sopenharmony_ci int fStencilBits = 0; 71cb93a386Sopenharmony_ci}; 72cb93a386Sopenharmony_ci 73cb93a386Sopenharmony_ci} // namespace sk_app 74cb93a386Sopenharmony_ci 75cb93a386Sopenharmony_ci#endif 76