gpu_surface_gl.h 1.5 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SHELL_GPU_GPU_SURFACE_GL_H_
#define SHELL_GPU_GPU_SURFACE_GL_H_

8
#include "flutter/fml/memory/weak_ptr.h"
9
#include "flutter/shell/common/surface.h"
10
#include "flutter/synchronization/debug_thread_checker.h"
11
#include "lib/fxl/macros.h"
12
#include "third_party/skia/include/gpu/GrContext.h"
13 14 15 16 17 18 19 20 21 22 23 24

namespace shell {

class GPUSurfaceGLDelegate {
 public:
  virtual bool GLContextMakeCurrent() = 0;

  virtual bool GLContextClearCurrent() = 0;

  virtual bool GLContextPresent() = 0;

  virtual intptr_t GLContextFBO() const = 0;
25 26

  virtual bool UseOffscreenSurface() const { return false; }
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
};

class GPUSurfaceGL : public Surface {
 public:
  GPUSurfaceGL(GPUSurfaceGLDelegate* delegate);

  ~GPUSurfaceGL() override;

  bool IsValid() override;

  std::unique_ptr<SurfaceFrame> AcquireFrame(const SkISize& size) override;

  GrContext* GetContext() override;

 private:
  GPUSurfaceGLDelegate* delegate_;
  sk_sp<GrContext> context_;
44
  sk_sp<SkSurface> onscreen_surface_;
45
  sk_sp<SkSurface> offscreen_surface_;
46
  bool valid_ = false;
47
  fml::WeakPtrFactory<GPUSurfaceGL> weak_factory_;
48

49
  bool CreateOrUpdateSurfaces(const SkISize& size);
50

51
  sk_sp<SkSurface> AcquireRenderSurface(const SkISize& size);
52 53 54

  bool PresentSurface(SkCanvas* canvas);

55
  FXL_DISALLOW_COPY_AND_ASSIGN(GPUSurfaceGL);
56 57 58 59 60
};

}  // namespace shell

#endif  // SHELL_GPU_GPU_SURFACE_GL_H_