Add a focused public API for src/record.
BUG=skia:2378 R=reed@google.com, robertphillips@google.com, mtklein@google.com, fmalita@chromium.org Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/233053005 git-svn-id: http://skia.googlecode.com/svn/trunk@14146 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
d923288e50
commit
18fd2b923a
@ -6,16 +6,19 @@
|
||||
'include_dirs': [
|
||||
'../include/config',
|
||||
'../include/core',
|
||||
'../include/record',
|
||||
],
|
||||
'direct_dependent_settings': {
|
||||
'include_dirs': [
|
||||
'../src/record',
|
||||
'../include/record', # World-public headers.
|
||||
'../src/record', # Skia-public headers.
|
||||
],
|
||||
},
|
||||
'sources': [
|
||||
'../src/record/SkRecorder.cpp',
|
||||
'../src/record/SkRecordCulling.cpp',
|
||||
'../src/record/SkRecordDraw.cpp',
|
||||
'../src/record/SkRecorder.cpp',
|
||||
'../src/record/SkRecording.cpp',
|
||||
],
|
||||
}]
|
||||
}
|
||||
|
@ -140,6 +140,7 @@
|
||||
'../tests/RecordDrawTest.cpp',
|
||||
'../tests/RecordTest.cpp',
|
||||
'../tests/RecorderTest.cpp',
|
||||
'../tests/RecordingTest.cpp',
|
||||
'../tests/RefCntTest.cpp',
|
||||
'../tests/RefDictTest.cpp',
|
||||
'../tests/RegionTest.cpp',
|
||||
|
67
include/record/SkRecording.h
Normal file
67
include/record/SkRecording.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef SkRecording_DEFINED
|
||||
#define SkRecording_DEFINED
|
||||
|
||||
#include "SkCanvas.h" // SkCanvas
|
||||
#include "SkTypes.h" // SkNoncopyable
|
||||
|
||||
// These are intentionally left opaque.
|
||||
class SkRecord;
|
||||
class SkRecorder;
|
||||
|
||||
namespace EXPERIMENTAL {
|
||||
|
||||
/** Easy mode interface to SkRecord-based SkCanvas recording.
|
||||
*
|
||||
* SkRecording* recording = SkRecording::Create(1920, 1080);
|
||||
*
|
||||
* SkCanvas* canvas = recording->canvas();
|
||||
* canvas->drawThis();
|
||||
* canvas->clipThat();
|
||||
* ...
|
||||
*
|
||||
* scoped_ptr<const SkPlayback> playback(SkRecording::Delete(recording));
|
||||
* playback->draw(&someCanvas);
|
||||
* playback->draw(&someOtherCanvas);
|
||||
*
|
||||
* SkPlayback is thread safe; SkRecording is not.
|
||||
*/
|
||||
|
||||
class SkPlayback : SkNoncopyable {
|
||||
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*);
|
||||
|
||||
const SkRecord* fRecord;
|
||||
|
||||
friend class SkRecording;
|
||||
};
|
||||
|
||||
class SkRecording : SkNoncopyable {
|
||||
public:
|
||||
// Result must be returned via SkRecording::Delete.
|
||||
static SkRecording* Create(int width, int height);
|
||||
|
||||
// Caller takes ownership of SkPlayback.
|
||||
static const SkPlayback* Delete(SkRecording*);
|
||||
|
||||
// Draws issued to this canvas will be replayed by SkPlayback::draw().
|
||||
// This pointer is owned by the SkRecording; the caller must not take ownership.
|
||||
SkCanvas* canvas();
|
||||
|
||||
private:
|
||||
SkRecording(int width, int height);
|
||||
~SkRecording();
|
||||
|
||||
SkRecorder* fRecorder;
|
||||
const SkRecord* fRecord;
|
||||
};
|
||||
|
||||
} // namespace EXPERIMENTAL
|
||||
|
||||
#endif//SkRecording_DEFINED
|
44
src/record/SkRecording.cpp
Normal file
44
src/record/SkRecording.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "SkRecording.h"
|
||||
|
||||
#include "SkRecord.h"
|
||||
#include "SkRecorder.h"
|
||||
#include "SkRecordDraw.h"
|
||||
|
||||
namespace EXPERIMENTAL {
|
||||
|
||||
SkPlayback::SkPlayback(const SkRecord* record) : fRecord(record) {}
|
||||
|
||||
SkPlayback::~SkPlayback() {
|
||||
SkDELETE(fRecord);
|
||||
}
|
||||
|
||||
void SkPlayback::draw(SkCanvas* canvas) const {
|
||||
SkASSERT(fRecord != NULL);
|
||||
SkRecordDraw(*fRecord, canvas);
|
||||
}
|
||||
|
||||
/*static*/ SkRecording* SkRecording::Create(int width, int height) {
|
||||
return SkNEW_ARGS(SkRecording, (width, height));
|
||||
}
|
||||
|
||||
SkRecording::SkRecording(int width, int height) {
|
||||
SkRecord* record = SkNEW(SkRecord);
|
||||
fRecorder = SkNEW_ARGS(SkRecorder, (SkRecorder::kReadWrite_Mode, record, width, height));
|
||||
fRecord = record;
|
||||
}
|
||||
|
||||
/*static*/ const SkPlayback* SkRecording::Delete(SkRecording* recording) {
|
||||
const SkRecord* record = recording->fRecord;
|
||||
SkDELETE(recording);
|
||||
return SkNEW_ARGS(SkPlayback, (record));
|
||||
}
|
||||
|
||||
SkRecording::~SkRecording() {
|
||||
SkDELETE(fRecorder);
|
||||
}
|
||||
|
||||
SkCanvas* SkRecording::canvas() {
|
||||
return fRecorder;
|
||||
}
|
||||
|
||||
} // namespace EXPERIMENTAL
|
18
tests/RecordingTest.cpp
Normal file
18
tests/RecordingTest.cpp
Normal file
@ -0,0 +1,18 @@
|
||||
#include "Test.h"
|
||||
|
||||
#include "SkRecording.h"
|
||||
|
||||
// Minimally exercise the public SkRecording API.
|
||||
|
||||
DEF_TEST(RecordingTest, r) {
|
||||
EXPERIMENTAL::SkRecording* recording = EXPERIMENTAL::SkRecording::Create(1920, 1080);
|
||||
|
||||
// Some very exciting commands here.
|
||||
recording->canvas()->clipRect(SkRect::MakeWH(320, 240));
|
||||
|
||||
SkAutoTDelete<const EXPERIMENTAL::SkPlayback> playback(
|
||||
EXPERIMENTAL::SkRecording::Delete(recording));
|
||||
|
||||
SkCanvas target;
|
||||
playback->draw(&target);
|
||||
}
|
Loading…
Reference in New Issue
Block a user