2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkRecording_DEFINED
9 #define SkRecording_DEFINED
11 #include "SkCanvas.h" // SkCanvas
12 #include "SkRefCnt.h" // SkAutoTUnref
13 #include "SkTemplates.h" // SkAutoTDelete
14 #include "SkTypes.h" // SkNoncopyable
16 // These are intentionally left opaque.
20 namespace EXPERIMENTAL {
22 /** Easy mode interface to SkRecord-based SkCanvas recording.
24 * scoped_ptr<SkRecording> recording(new SkRecording(1920, 1080));
25 * skia::RefPtr<SkCanvas> canvas(skia::SharePtr(recording->canvas()));
31 * canvas.clear(); // You must deref the canvas before you may call releasePlayback().
32 * scoped_ptr<const SkPlayback> playback(recording->releasePlayback());
33 * playback->draw(&someCanvas);
34 * playback->draw(&someOtherCanvas);
36 * SkPlayback is thread safe; SkRecording is not.
39 class SK_API SkPlayback : SkNoncopyable {
41 // Remember, if you've got an SkPlayback*, you probably own it. Don't forget to delete it!
44 // Draw recorded commands into a canvas.
45 void draw(SkCanvas*) const;
48 explicit SkPlayback(const SkRecord*);
50 SkAutoTDelete<const SkRecord> fRecord;
52 friend class SkRecording;
55 class SK_API SkRecording : SkNoncopyable {
57 SkRecording(int width, int height);
60 // Draws issued to this canvas will be replayed by SkPlayback::draw().
61 // Any refs held on canvas() must be dropped before you may call releasePlayback().
64 // Release exclusive ownership of an SkPlayback to the caller.
65 // Any refs held on canvas() must be dropped before you may call releasePlayback().
66 SkPlayback* releasePlayback();
69 SkAutoTDelete<SkRecord> fRecord;
70 SkAutoTUnref<SkRecorder> fRecorder;
73 } // namespace EXPERIMENTAL
75 #endif//SkRecording_DEFINED