2014-04-11 18:33:31 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-04-10 23:30:59 +00:00
|
|
|
#ifndef SkRecording_DEFINED
|
|
|
|
#define SkRecording_DEFINED
|
|
|
|
|
2014-04-24 15:22:55 +00:00
|
|
|
#include "SkCanvas.h" // SkCanvas
|
|
|
|
#include "SkRefCnt.h" // SkAutoTUnref
|
|
|
|
#include "SkTemplates.h" // SkAutoTDelete
|
|
|
|
#include "SkTypes.h" // SkNoncopyable
|
2014-04-10 23:30:59 +00:00
|
|
|
|
|
|
|
// These are intentionally left opaque.
|
|
|
|
class SkRecord;
|
|
|
|
class SkRecorder;
|
|
|
|
|
|
|
|
namespace EXPERIMENTAL {
|
|
|
|
|
|
|
|
/** Easy mode interface to SkRecord-based SkCanvas recording.
|
|
|
|
*
|
2014-04-24 15:22:55 +00:00
|
|
|
* scoped_ptr<SkRecording> recording(new SkRecording(1920, 1080));
|
|
|
|
* skia::RefPtr<SkCanvas> canvas(skia::SharePtr(recording->canvas()));
|
2014-04-10 23:30:59 +00:00
|
|
|
*
|
|
|
|
* canvas->drawThis();
|
|
|
|
* canvas->clipThat();
|
|
|
|
* ...
|
|
|
|
*
|
2014-04-24 15:22:55 +00:00
|
|
|
* canvas.clear(); // You must deref the canvas before you may call releasePlayback().
|
|
|
|
* scoped_ptr<const SkPlayback> playback(recording->releasePlayback());
|
2014-04-10 23:30:59 +00:00
|
|
|
* playback->draw(&someCanvas);
|
|
|
|
* playback->draw(&someOtherCanvas);
|
|
|
|
*
|
|
|
|
* SkPlayback is thread safe; SkRecording is not.
|
|
|
|
*/
|
|
|
|
|
2014-04-28 21:04:32 +00:00
|
|
|
class SK_API SkPlayback : SkNoncopyable {
|
2014-04-10 23:30:59 +00:00
|
|
|
public:
|
|
|
|
// Remember, if you've got an SkPlayback*, you probably own it. Don't forget to delete it!
|
|
|
|
~SkPlayback();
|
|
|
|
|
|
|
|
// Draw recorded commands into a canvas.
|
|
|
|
void draw(SkCanvas*) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit SkPlayback(const SkRecord*);
|
|
|
|
|
2014-04-24 15:22:55 +00:00
|
|
|
SkAutoTDelete<const SkRecord> fRecord;
|
2014-04-10 23:30:59 +00:00
|
|
|
|
|
|
|
friend class SkRecording;
|
|
|
|
};
|
|
|
|
|
2014-04-28 21:04:32 +00:00
|
|
|
class SK_API SkRecording : SkNoncopyable {
|
2014-04-10 23:30:59 +00:00
|
|
|
public:
|
2014-04-24 15:22:55 +00:00
|
|
|
SkRecording(int width, int height);
|
|
|
|
~SkRecording();
|
2014-04-10 23:30:59 +00:00
|
|
|
|
|
|
|
// Draws issued to this canvas will be replayed by SkPlayback::draw().
|
2014-04-24 15:22:55 +00:00
|
|
|
// Any refs held on canvas() must be dropped before you may call releasePlayback().
|
2014-04-10 23:30:59 +00:00
|
|
|
SkCanvas* canvas();
|
|
|
|
|
2014-04-24 15:22:55 +00:00
|
|
|
// Release exclusive ownership of an SkPlayback to the caller.
|
|
|
|
// Any refs held on canvas() must be dropped before you may call releasePlayback().
|
|
|
|
SkPlayback* releasePlayback();
|
2014-04-10 23:30:59 +00:00
|
|
|
|
2014-04-24 15:22:55 +00:00
|
|
|
private:
|
|
|
|
SkAutoTDelete<SkRecord> fRecord;
|
|
|
|
SkAutoTUnref<SkRecorder> fRecorder;
|
2014-04-10 23:30:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace EXPERIMENTAL
|
|
|
|
|
|
|
|
#endif//SkRecording_DEFINED
|