1/* 2 * Copyright 2017 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 SkDeferredDisplayListMaker_DEFINED 9#define SkDeferredDisplayListMaker_DEFINED 10 11#include "SkRefCnt.h" 12 13#include "../private/SkDeferredDisplayList.h" 14#include "../private/SkSurfaceCharacterization.h" 15 16class GrContext; 17 18class SkCanvas; 19class SkSurface; 20 21/* 22 * This class is intended to be used as: 23 * Get an SkSurfaceCharacterization representing the intended gpu-backed destination SkSurface 24 * Create one of these (an SkDDLMaker) on the stack 25 * Get the canvas and render into it 26 * Snap off and hold on to an SkDeferredDisplayList 27 * Once your app actually needs the pixels, call SkSurface::draw(SkDeferredDisplayList*) 28 * 29 * This class never accesses the GPU but performs all the cpu work it can. It 30 * is thread-safe (i.e., one can break a scene into tiles and perform their cpu-side 31 * work in parallel ahead of time). 32 */ 33class SK_API SkDeferredDisplayListRecorder { 34public: 35 SkDeferredDisplayListRecorder(const SkSurfaceCharacterization&); 36 ~SkDeferredDisplayListRecorder(); 37 38 const SkSurfaceCharacterization& characterization() const { 39 return fCharacterization; 40 } 41 42 // The backing canvas will become invalid (and this entry point will return 43 // null) once 'detach' is called. 44 // Note: ownership of the SkCanvas is not transfered via this call. 45 SkCanvas* getCanvas(); 46 47 std::unique_ptr<SkDeferredDisplayList> detach(); 48 49private: 50 bool init(); 51 52 const SkSurfaceCharacterization fCharacterization; 53 54#ifndef SK_RASTER_RECORDER_IMPLEMENTATION 55#if SK_SUPPORT_GPU 56 sk_sp<GrContext> fContext; 57#endif 58 sk_sp<SkDeferredDisplayList::LazyProxyData> fLazyProxyData; 59#endif 60 sk_sp<SkSurface> fSurface; 61}; 62 63#endif 64