1 /*
2  * Copyright 2014 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 
8 #ifndef SkSurface_Gpu_DEFINED
9 #define SkSurface_Gpu_DEFINED
10 
11 #include "GrTypesPriv.h"
12 #include "SkSurface_Base.h"
13 
14 #if SK_SUPPORT_GPU
15 
16 class SkGpuDevice;
17 
18 class SkSurface_Gpu : public SkSurface_Base {
19 public:
20     SkSurface_Gpu(sk_sp<SkGpuDevice>);
21     ~SkSurface_Gpu() override;
22 
23     // This is an internal-only factory
24     static sk_sp<SkSurface> MakeWrappedRenderTarget(GrContext*, sk_sp<GrRenderTargetContext>);
25 
26     GrBackendTexture onGetBackendTexture(BackendHandleAccess) override;
27     GrBackendRenderTarget onGetBackendRenderTarget(BackendHandleAccess) override;
28 
29     SkCanvas* onNewCanvas() override;
30     sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
31     sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;
32     void onWritePixels(const SkPixmap&, int x, int y) override;
33     void onCopyOnWrite(ContentChangeMode) override;
34     void onDiscard() override;
35     GrSemaphoresSubmitted onFlush(BackendSurfaceAccess access, GrFlushFlags flags,
36                                   int numSemaphores,
37                                   GrBackendSemaphore signalSemaphores[],
38                                   GrGpuFinishedProc finishedProc,
39                                   GrGpuFinishedContext finishedContext) override;
40     bool onWait(int numSemaphores, const GrBackendSemaphore* waitSemaphores) override;
41     bool onCharacterize(SkSurfaceCharacterization*) const override;
42     bool isCompatible(const SkSurfaceCharacterization&) const;
43     bool onDraw(const SkDeferredDisplayList*) override;
44 
getDevice()45     SkGpuDevice* getDevice() { return fDevice.get(); }
46 
47     static bool Valid(const SkImageInfo&);
48     static bool Valid(const GrCaps*, GrPixelConfig, SkColorSpace*);
49 
50 private:
51     sk_sp<SkGpuDevice> fDevice;
52 
53     typedef SkSurface_Base INHERITED;
54 };
55 
56 #endif // SK_SUPPORT_GPU
57 
58 #endif // SkSurface_Gpu_DEFINED
59