2011-04-26 17:41:56 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SkGPipe_DEFINED
|
|
|
|
#define SkGPipe_DEFINED
|
|
|
|
|
|
|
|
#include "SkWriter32.h"
|
2011-05-23 12:21:05 +00:00
|
|
|
#include "SkFlattenable.h"
|
2011-04-26 17:41:56 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
|
|
|
|
|
|
|
class SkGPipeReader {
|
|
|
|
public:
|
|
|
|
SkGPipeReader(SkCanvas* target);
|
|
|
|
~SkGPipeReader();
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
kDone_Status, //!< no more data expected from reader
|
|
|
|
kEOF_Status, //!< need more data from reader
|
2011-06-16 21:08:19 +00:00
|
|
|
kError_Status, //!< encountered error
|
|
|
|
kReadAtom_Status//!< finished reading an atom
|
2011-04-26 17:41:56 +00:00
|
|
|
};
|
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
// data must be 4-byte aligned
|
|
|
|
// length must be a multiple of 4
|
2011-06-16 21:08:19 +00:00
|
|
|
Status playback(const void* data, size_t length, size_t* bytesRead = NULL,
|
|
|
|
bool readAtom = false);
|
2011-04-26 17:41:56 +00:00
|
|
|
private:
|
|
|
|
SkCanvas* fCanvas;
|
|
|
|
class SkGPipeState* fState;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
class SkGPipeController {
|
2011-04-26 20:06:08 +00:00
|
|
|
public:
|
|
|
|
/**
|
2011-05-03 21:26:46 +00:00
|
|
|
* Called periodically by the writer, to get a working buffer of RAM to
|
|
|
|
* write into. The actual size of the block is also returned, and must be
|
|
|
|
* actual >= minRequest. If NULL is returned, then actual is ignored and
|
|
|
|
* writing will stop.
|
2011-04-26 20:06:08 +00:00
|
|
|
*
|
2011-05-03 21:26:46 +00:00
|
|
|
* The returned block must be 4-byte aligned, and actual must be a
|
|
|
|
* multiple of 4.
|
|
|
|
* minRequest will always be a multiple of 4.
|
|
|
|
*/
|
|
|
|
virtual void* requestBlock(size_t minRequest, size_t* actual) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is called each time some atomic portion of the data has been
|
|
|
|
* written to the block (most recently returned by requestBlock()).
|
|
|
|
* If bytes == 0, then the writer has finished.
|
2011-04-26 20:06:08 +00:00
|
|
|
*
|
2011-05-03 21:26:46 +00:00
|
|
|
* bytes will always be a multiple of 4.
|
2011-04-26 20:06:08 +00:00
|
|
|
*/
|
2011-05-03 21:26:46 +00:00
|
|
|
virtual void notifyWritten(size_t bytes) = 0;
|
2011-04-26 20:06:08 +00:00
|
|
|
};
|
|
|
|
|
2011-04-26 17:41:56 +00:00
|
|
|
class SkGPipeWriter {
|
|
|
|
public:
|
|
|
|
SkGPipeWriter();
|
|
|
|
~SkGPipeWriter();
|
|
|
|
|
|
|
|
bool isRecording() const { return NULL != fCanvas; }
|
2011-05-23 12:21:05 +00:00
|
|
|
|
|
|
|
enum Flags {
|
|
|
|
kCrossProcess_Flag = 1 << 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0);
|
2011-04-26 17:41:56 +00:00
|
|
|
|
2011-05-03 21:26:46 +00:00
|
|
|
// called in destructor, but can be called sooner once you know there
|
|
|
|
// should be no more drawing calls made into the recording canvas.
|
|
|
|
void endRecording();
|
2011-04-26 17:41:56 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
class SkGPipeCanvas* fCanvas;
|
2011-05-03 21:26:46 +00:00
|
|
|
SkGPipeController* fController;
|
2011-05-23 12:21:05 +00:00
|
|
|
SkFactorySet fFactorySet;
|
2011-04-26 17:41:56 +00:00
|
|
|
SkWriter32 fWriter;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|