reed 2016-01-08 06:30:14 -08:00 committed by Commit bot
parent 57fa241d6f
commit 7c554222dd
22 changed files with 0 additions and 3448 deletions

View File

@ -623,7 +623,6 @@ static Sink* create_sink(const SkCommandLineConfig* config) {
static Sink* create_via(const SkString& tag, Sink* wrapped) {
#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
VIA("twice", ViaTwice, wrapped);
VIA("pipe", ViaPipe, wrapped);
VIA("serialize", ViaSerialization, wrapped);
VIA("2ndpic", ViaSecondPicture, wrapped);
VIA("sp", ViaSingletonPictures, wrapped);

View File

@ -6,7 +6,6 @@
*/
#include "DMSrcSink.h"
#include "SamplePipeControllers.h"
#include "SkAndroidCodec.h"
#include "SkCodec.h"
#include "SkCommonFlags.h"
@ -1060,16 +1059,6 @@ Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkSt
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
SkGPipeWriter pipe;
const uint32_t kFlags = 0;
return src.draw(pipe.startRecording(&controller, kFlags, size.width(), size.height()));
});
}
Error ViaRemote::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* target) {
SkAutoTDelete<SkRemote::Encoder> decoder(SkRemote::NewDecoder(target));

View File

@ -15,7 +15,6 @@
#include "SkBitmapRegionDecoder.h"
#include "SkCanvas.h"
#include "SkData.h"
#include "SkGPipe.h"
#include "SkPicture.h"
#include "gm.h"
@ -316,12 +315,6 @@ private:
const SkMatrix fMatrix;
};
class ViaPipe : public Via {
public:
explicit ViaPipe(Sink* sink) : Via(sink) {}
Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
class ViaRemote : public Via {
public:
ViaRemote(bool cache, Sink* sink) : Via(sink), fCache(cache) {}

View File

@ -10,13 +10,11 @@
'mac_bundle' : 1,
'include_dirs' : [
'../include/pipe',
'../experimental/FileReaderApp',
'../experimental/SimpleCocoaApp',
],
'sources': [
'../experimental/FileReaderApp/ReaderView.cpp',
'../src/pipe/SkGPipeRead.cpp',
],
'sources!': [
'../src/utils/mac/SkOSWindow_Mac.cpp',

View File

@ -17,7 +17,6 @@
'../src/lazy',
'../gm', # needed to pull gm.h
'../samplecode', # To pull SampleApp.h and SampleCode.h
'../src/pipe/utils', # For TiledPipeController
'../src/utils/debugger',
'../tools',
'../experimental',
@ -135,10 +134,6 @@
'../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp',
'../experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h',
# TiledPipeController
'../src/pipe/utils/SamplePipeControllers.h',
'../src/pipe/utils/SamplePipeControllers.cpp',
# Lua
'../src/utils/SkLuaCanvas.cpp',
'../src/utils/SkLua.cpp',

View File

@ -21,7 +21,6 @@
'../include/config',
'../include/core',
'../include/pathops',
'../include/pipe',
'../include/ports',
'../include/private',
'../include/utils',
@ -108,7 +107,6 @@
'../include/config',
'../include/core',
'../include/pathops',
'../include/pipe',
],
'conditions': [
[ 'skia_os == "mac"', {

View File

@ -312,9 +312,6 @@
# '<(skia_src_path)/image/SkSurface_Gpu.cpp',
'<(skia_src_path)/image/SkSurface_Raster.cpp',
'<(skia_src_path)/pipe/SkGPipeRead.cpp',
'<(skia_src_path)/pipe/SkGPipeWrite.cpp',
'<(skia_include_path)/core/SkBBHFactory.h',
'<(skia_include_path)/core/SkBitmap.h',
'<(skia_include_path)/core/SkBitmapDevice.h',

View File

@ -12,7 +12,6 @@
'../src/effects',
'../src/images',
'../src/lazy',
'../src/pipe/utils/',
'../src/utils',
'../src/utils/debugger',
'../tests',
@ -42,7 +41,6 @@
'../dm/DMJsonWriter.cpp',
'../gm/gm.cpp',
'../src/pipe/utils/SamplePipeControllers.cpp',
'../src/utils/debugger/SkDebugCanvas.cpp',
'../src/utils/debugger/SkDrawCommand.cpp',
'../src/utils/debugger/SkObjectParser.cpp',

View File

@ -17,7 +17,6 @@
'../src/effects',
'../src/lazy',
'../src/pathops',
'../src/pipe/utils',
'../src/utils',
],
'dependencies': [

View File

@ -15,7 +15,6 @@
'../src/pathops',
'../src/pdf',
'../src/ports',
'../src/pipe/utils',
'../src/utils',
'../src/utils/debugger',
],
@ -58,7 +57,6 @@
'../src/utils/debugger/SkDebugCanvas.cpp',
'../src/utils/debugger/SkObjectParser.h',
'../src/utils/debugger/SkObjectParser.cpp',
'../src/pipe/utils/SamplePipeControllers.cpp',
],
'sources!': [
'../tests/SkpSkGrTest.cpp',

View File

@ -431,7 +431,6 @@
'<(skia_include_path)/gpu',
'<(skia_include_path)/images',
'<(skia_include_path)/pathops',
'<(skia_include_path)/pipe',
'<(skia_include_path)/ports',
'<(skia_include_path)/svg/parser',
'<(skia_include_path)/utils',

View File

@ -22,7 +22,6 @@
'../include/gpu',
'../include/images',
'../include/pathops',
'../include/pipe',
'../include/private',
'../include/utils',
'../include/utils/mac',

View File

@ -1,174 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkGPipe_DEFINED
#define SkGPipe_DEFINED
#include "SkFlattenable.h"
#include "SkPicture.h"
#include "SkWriter32.h"
class SkCanvas;
// XLib.h might have defined Status already (ugh)
#ifdef Status
#undef Status
#endif
class SkGPipeReader {
public:
SkGPipeReader();
SkGPipeReader(SkCanvas* target);
~SkGPipeReader();
enum Status {
kDone_Status, //!< no more data expected from reader
kEOF_Status, //!< need more data from reader
kError_Status, //!< encountered error
kReadAtom_Status//!< finished reading an atom
};
enum PlaybackFlags {
kReadAtom_PlaybackFlag = 0x1, //!< playback a single command from the stream
kSilent_PlaybackFlag = 0x2, //!< playback without drawing
};
void setCanvas(SkCanvas*);
/**
* Set a function for decoding bitmaps that have encoded data.
*/
void setBitmapDecoder(SkPicture::InstallPixelRefProc proc) { fProc = proc; }
// data must be 4-byte aligned
// length must be a multiple of 4
Status playback(const void* data, size_t length, uint32_t playbackFlags = 0,
size_t* bytesRead = NULL);
private:
SkCanvas* fCanvas;
class SkGPipeState* fState;
SkPicture::InstallPixelRefProc fProc;
};
///////////////////////////////////////////////////////////////////////////////
class SkGPipeCanvas;
class SkGPipeController {
public:
SkGPipeController() : fCanvas(NULL) {}
virtual ~SkGPipeController();
/**
* 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.
*
* 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.
*
* bytes will always be a multiple of 4.
*/
virtual void notifyWritten(size_t bytes) = 0;
virtual int numberOfReaders() const { return 1; }
/**
* Release resource references that are held in internal caches.
* This must only be called after the pipe has been completely flushed.
*/
void purgeCaches();
private:
friend class SkGPipeWriter;
void setCanvas(SkGPipeCanvas*);
SkGPipeCanvas* fCanvas;
};
class SkGPipeWriter {
public:
SkGPipeWriter();
~SkGPipeWriter();
bool isRecording() const { return SkToBool(fCanvas); }
enum Flags {
/**
* Tells the writer that the reader will be in a different process, so
* (for example) we cannot put function pointers in the stream.
*/
kCrossProcess_Flag = 1 << 0,
/**
* Only meaningful if kCrossProcess_Flag is set. Tells the writer that
* in spite of being cross process, it will have shared address space
* with the reader, so the two can share large objects (like SkBitmaps).
*/
kSharedAddressSpace_Flag = 1 << 1,
/**
* Tells the writer that there will be multiple threads reading the stream
* simultaneously.
*/
kSimultaneousReaders_Flag = 1 << 2,
};
SkCanvas* startRecording(SkGPipeController*, uint32_t flags = 0,
uint32_t width = kDefaultRecordingCanvasSize,
uint32_t height = kDefaultRecordingCanvasSize);
// 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();
/**
* Tells the writer to commit all recorded draw commands to the
* controller immediately.
* @param detachCurrentBlock Set to true to request that the next draw
* command be recorded in a new block.
*/
void flushRecording(bool detachCurrentBlock);
/**
* Return the amount of bytes being used for recording. Note that this
* does not include the amount of storage written to the stream, which is
* controlled by the SkGPipeController.
* Currently only returns the amount used for SkBitmaps, since they are
* potentially unbounded (if the client is not calling playback).
*/
size_t storageAllocatedForRecording() const;
/**
* Attempt to reduce the storage allocated for recording by evicting
* cache resources.
* @param bytesToFree minimum number of bytes that should be attempted to
* be freed.
* @return number of bytes actually freed.
*/
size_t freeMemoryIfPossible(size_t bytesToFree);
private:
enum {
kDefaultRecordingCanvasSize = 32767,
};
SkGPipeCanvas* fCanvas;
SkWriter32 fWriter;
};
#endif

View File

@ -10,14 +10,12 @@
#include "OverView.h"
#include "Resources.h"
#include "SampleCode.h"
#include "SamplePipeControllers.h"
#include "SkAnimTimer.h"
#include "SkCanvas.h"
#include "SkCommandLineFlags.h"
#include "SkData.h"
#include "SkDevice.h"
#include "SkDocument.h"
#include "SkGPipe.h"
#include "SkGraphics.h"
#include "SkImageEncoder.h"
#include "SkOSFile.h"
@ -71,17 +69,6 @@ public:
};
#endif // SAMPLE_PDF_FILE_VIEWER
#define PIPE_FILEx
#ifdef PIPE_FILE
#define FILE_PATH "/path/to/drawing.data"
#endif
#define PIPE_NETx
#ifdef PIPE_NET
#include "SkSockets.h"
SkTCPServer gServer;
#endif
#if SK_COMMAND_BUFFER
#define DEFAULT_TO_COMMAND_BUFFER 1
#elif SK_ANGLE
@ -835,12 +822,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
static SkTaskGroup::Enabler enabled(-1);
gSampleWindow = this;
#ifdef PIPE_FILE
//Clear existing file or create file if it doesn't exist
FILE* f = fopen(FILE_PATH, "wb");
fclose(f);
#endif
fDeviceType = kRaster_DeviceType;
#if SK_SUPPORT_GPU
if (FLAGS_gpu) {
@ -864,7 +845,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
fRotate = false;
fPerspAnim = false;
fRequestGrabImage = false;
fPipeState = SkOSMenu::kOffState;
fTilingMode = kNo_Tiling;
fMeasureFPS = false;
fLCDState = SkOSMenu::kMixedState;
@ -927,10 +907,6 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
nullptr);
fAppMenu->assignKeyEquivalentToItem(itemID, 'h');
fUsePipeMenuItemID = fAppMenu->appendTriState("Pipe", "Pipe" , sinkID,
fPipeState);
fAppMenu->assignKeyEquivalentToItem(fUsePipeMenuItemID, 'P');
itemID =fAppMenu->appendList("Tiling", "Tiling", sinkID, fTilingMode,
gTilingInfo[kNo_Tiling].label,
gTilingInfo[kAbs_128x128_Tiling].label,
@ -1624,16 +1600,6 @@ bool SampleWindow::onEvent(const SkEvent& evt) {
this->setDeviceType((DeviceType)selected);
return true;
}
if (SkOSMenu::FindTriState(evt, "Pipe", &fPipeState)) {
#ifdef PIPE_NET
if (!fPipeState != SkOSMenu::kOnState)
gServer.disconnectAll();
#endif
(void)SampleView::SetUsePipe(curr_view(this), fPipeState);
this->updateTitle();
this->inval(nullptr);
return true;
}
if (SkOSMenu::FindSwitchState(evt, "Slide Show", nullptr)) {
this->toggleSlideshow();
return true;
@ -2018,12 +1984,6 @@ void SampleWindow::loadView(SkView* view) {
//repopulate the slide menu when a view is loaded
fSlideMenu->reset();
(void)SampleView::SetUsePipe(view, fPipeState);
if (SampleView::IsSampleView(view)) {
SampleView* sampleView = (SampleView*)view;
sampleView->requestMenu(fSlideMenu);
sampleView->onTileSizeChanged(this->tileSize());
}
this->onUpdateMenu(fSlideMenu);
this->updateTitle();
}
@ -2103,22 +2063,6 @@ void SampleWindow::updateTitle() {
title.appendf(" %8.4f ms", fMeasureFPS_Time / (float)FPS_REPEAT_COUNT);
}
SkView* view = curr_view(this);
if (SampleView::IsSampleView(view)) {
switch (fPipeState) {
case SkOSMenu::kOnState:
title.prepend("<Pipe> ");
break;
case SkOSMenu::kMixedState:
title.prepend("<Tiled Pipe> ");
break;
default:
break;
}
title.prepend("! ");
}
#if SK_SUPPORT_GPU
if (IsGpuDeviceType(fDeviceType) &&
fDevManager &&
@ -2181,7 +2125,6 @@ void SampleWindow::onSizeChange() {
static const char is_sample_view_tag[] = "sample-is-sample-view";
static const char repeat_count_tag[] = "sample-set-repeat-count";
static const char set_use_pipe_tag[] = "sample-set-use-pipe";
bool SampleView::IsSampleView(SkView* view) {
SkEvent evt(is_sample_view_tag);
@ -2194,24 +2137,11 @@ bool SampleView::SetRepeatDraw(SkView* view, int count) {
return view->doEvent(evt);
}
bool SampleView::SetUsePipe(SkView* view, SkOSMenu::TriState state) {
SkEvent evt;
evt.setS32(set_use_pipe_tag, state);
return view->doEvent(evt);
}
bool SampleView::onEvent(const SkEvent& evt) {
if (evt.isType(repeat_count_tag)) {
fRepeatCount = evt.getFast32();
return true;
}
int32_t pipeHolder;
if (evt.findS32(set_use_pipe_tag, &pipeHolder)) {
fPipeState = static_cast<SkOSMenu::TriState>(pipeHolder);
return true;
}
return this->INHERITED::onEvent(evt);
}
@ -2222,102 +2152,6 @@ bool SampleView::onQuery(SkEvent* evt) {
return this->INHERITED::onQuery(evt);
}
class SimplePC : public SkGPipeController {
public:
SimplePC(SkCanvas* target);
~SimplePC();
virtual void* requestBlock(size_t minRequest, size_t* actual);
virtual void notifyWritten(size_t bytes);
private:
SkGPipeReader fReader;
void* fBlock;
size_t fBlockSize;
size_t fBytesWritten;
int fAtomsWritten;
SkGPipeReader::Status fStatus;
size_t fTotalWritten;
};
SimplePC::SimplePC(SkCanvas* target) : fReader(target) {
fBlock = nullptr;
fBlockSize = fBytesWritten = 0;
fStatus = SkGPipeReader::kDone_Status;
fTotalWritten = 0;
fAtomsWritten = 0;
fReader.setBitmapDecoder(&SkImageDecoder::DecodeMemory);
}
SimplePC::~SimplePC() {
// SkASSERT(SkGPipeReader::kDone_Status == fStatus);
if (fTotalWritten) {
SkDebugf("--- %d bytes %d atoms, status %d\n", fTotalWritten,
fAtomsWritten, fStatus);
#ifdef PIPE_FILE
//File is open in append mode
FILE* f = fopen(FILE_PATH, "ab");
SkASSERT(f != nullptr);
fwrite((const char*)fBlock + fBytesWritten, 1, bytes, f);
fclose(f);
#endif
#ifdef PIPE_NET
if (fAtomsWritten > 1 && fTotalWritten > 4) { //ignore done
gServer.acceptConnections();
gServer.writePacket(fBlock, fTotalWritten);
}
#endif
}
sk_free(fBlock);
}
void* SimplePC::requestBlock(size_t minRequest, size_t* actual) {
sk_free(fBlock);
fBlockSize = minRequest * 4;
fBlock = sk_malloc_throw(fBlockSize);
fBytesWritten = 0;
*actual = fBlockSize;
return fBlock;
}
void SimplePC::notifyWritten(size_t bytes) {
SkASSERT(fBytesWritten + bytes <= fBlockSize);
fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes);
SkASSERT(SkGPipeReader::kError_Status != fStatus);
fBytesWritten += bytes;
fTotalWritten += bytes;
fAtomsWritten += 1;
}
void SampleView::draw(SkCanvas* canvas) {
if (SkOSMenu::kOffState == fPipeState) {
this->INHERITED::draw(canvas);
} else {
SkGPipeWriter writer;
SimplePC controller(canvas);
SkBitmap bitmap = capture_bitmap(canvas);
TiledPipeController tc(bitmap, &SkImageDecoder::DecodeMemory, &canvas->getTotalMatrix());
SkGPipeController* pc;
if (SkOSMenu::kMixedState == fPipeState) {
pc = &tc;
} else {
pc = &controller;
}
uint32_t flags = SkGPipeWriter::kCrossProcess_Flag;
canvas = writer.startRecording(pc, flags);
//Must draw before controller goes out of scope and sends data
this->INHERITED::draw(canvas);
//explicitly end recording to ensure writer is flushed before the memory
//is freed in the deconstructor of the controller
writer.endRecording();
}
}
void SampleView::onDraw(SkCanvas* canvas) {
if (!fHaveCalledOnceBeforeDraw) {
fHaveCalledOnceBeforeDraw = true;

View File

@ -191,12 +191,6 @@ private:
bool fMagnify;
int fTilingMode;
SkOSMenu::TriState fPipeState; // Mixed uses a tiled pipe
// On uses a normal pipe
// Off uses no pipe
int fUsePipeMenuItemID;
// The following are for the 'fatbits' drawing
// Latest position of the mouse.
int fMouseX, fMouseY;

View File

@ -137,7 +137,6 @@ protected:
// overrides
virtual bool onEvent(const SkEvent& evt);
virtual bool onQuery(SkEvent* evt);
virtual void draw(SkCanvas*);
virtual void onDraw(SkCanvas*);
SkOSMenu::TriState fPipeState;

View File

@ -1,313 +0,0 @@
/*
* Copyright 2011 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkGPipePriv_DEFINED
#define SkGPipePriv_DEFINED
#include "SkTypes.h"
#define UNIMPLEMENTED
// these must be contiguous, 0...N-1
enum PaintFlats {
kColorFilter_PaintFlat,
kDrawLooper_PaintFlat,
kImageFilter_PaintFlat,
kMaskFilter_PaintFlat,
kPathEffect_PaintFlat,
kRasterizer_PaintFlat,
kShader_PaintFlat,
kXfermode_PaintFlat,
kLast_PaintFlat = kXfermode_PaintFlat
};
#define kCount_PaintFlats (kLast_PaintFlat + 1)
enum DrawOps {
kSkip_DrawOp, // skip an addition N bytes (N == data)
// these match Canvas apis
kClipPath_DrawOp,
kClipRegion_DrawOp,
kClipRect_DrawOp,
kClipRRect_DrawOp,
kConcat_DrawOp,
kDrawAtlas_DrawOp,
kDrawBitmap_DrawOp,
kDrawBitmapNine_DrawOp,
kDrawBitmapRect_DrawOp,
kDrawDRRect_DrawOp,
kDrawImage_DrawOp,
kDrawImageRect_DrawOp,
kDrawImageNine_DrawOp,
kDrawOval_DrawOp,
kDrawPaint_DrawOp,
kDrawPatch_DrawOp,
kDrawPath_DrawOp,
kDrawPicture_DrawOp,
kDrawPoints_DrawOp,
kDrawPosText_DrawOp,
kDrawPosTextH_DrawOp,
kDrawRect_DrawOp,
kDrawRRect_DrawOp,
kDrawText_DrawOp,
kDrawTextBlob_DrawOp,
kDrawTextOnPath_DrawOp,
kDrawVertices_DrawOp,
kRestore_DrawOp,
kRotate_DrawOp,
kSave_DrawOp,
kSaveLayer_DrawOp,
kScale_DrawOp,
kSetMatrix_DrawOp,
kSkew_DrawOp,
kTranslate_DrawOp,
kPaintOp_DrawOp,
kSetTypeface_DrawOp,
kSetAnnotation_DrawOp,
kDef_Typeface_DrawOp,
kDef_Flattenable_DrawOp,
kDef_Bitmap_DrawOp,
kDef_Factory_DrawOp,
// these are signals to playback, not drawing verbs
kReportFlags_DrawOp,
kShareBitmapHeap_DrawOp,
kShareImageHeap_DrawOp,
kDone_DrawOp,
};
/**
* DrawOp packs into a 32bit int as follows
*
* DrawOp:8 - Flags:4 - Data:20
*
* Flags and Data are called out separately, so we can reuse Data between
* different Ops that might have different Flags. e.g. Data might be a Paint
* index for both drawRect (no flags) and saveLayer (does have flags).
*
* All Ops that take a SkPaint use their Data field to store the index to
* the paint (previously defined with kPaintOp_DrawOp).
*/
#define DRAWOPS_OP_BITS 8
#define DRAWOPS_FLAG_BITS 4
#define DRAWOPS_DATA_BITS 20
#define DRAWOPS_OP_MASK ((1 << DRAWOPS_OP_BITS) - 1)
#define DRAWOPS_FLAG_MASK ((1 << DRAWOPS_FLAG_BITS) - 1)
#define DRAWOPS_DATA_MASK ((1 << DRAWOPS_DATA_BITS) - 1)
static inline unsigned DrawOp_unpackOp(uint32_t op32) {
return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
}
static inline unsigned DrawOp_unpackFlags(uint32_t op32) {
return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
}
static inline unsigned DrawOp_unpackData(uint32_t op32) {
return op32 & DRAWOPS_DATA_MASK;
}
static inline uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigned data) {
SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
(flags << DRAWOPS_DATA_BITS) |
data;
}
/** DrawOp specific flag bits
*/
enum {
kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
};
enum {
kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
};
enum {
kDrawVertices_HasTexs_DrawOpFlag = 1 << 0,
kDrawVertices_HasColors_DrawOpFlag = 1 << 1,
kDrawVertices_HasIndices_DrawOpFlag = 1 << 2,
kDrawVertices_HasXfermode_DrawOpFlag = 1 << 3,
};
enum {
kDrawAtlas_HasPaint_DrawOpFlag = 1 << 0,
kDrawAtlas_HasColors_DrawOpFlag = 1 << 1,
kDrawAtlas_HasCull_DrawOpFlag = 1 << 2,
};
// These are shared between drawbitmap and drawimage
enum {
kDrawBitmap_HasPaint_DrawOpFlag = 1 << 0,
// Specific to drawBitmapRect, but needs to be different from HasPaint,
// which is used for all drawBitmap calls, so include it here.
kDrawBitmap_HasSrcRect_DrawOpFlag = 1 << 1,
// SkCanvas::DrawBitmapRectFlags::kBleed_DrawBitmapRectFlag is
// converted into and out of this flag to save space
kDrawBitmap_Bleed_DrawOpFlag = 1 << 2,
};
enum {
kClip_HasAntiAlias_DrawOpFlag = 1 << 0,
};
///////////////////////////////////////////////////////////////////////////////
class BitmapInfo : SkNoncopyable {
public:
BitmapInfo(SkBitmap* bitmap, uint32_t genID, int toBeDrawnCount)
: fBitmap(bitmap)
, fGenID(genID)
, fBytesAllocated(0)
, fMoreRecentlyUsed(nullptr)
, fLessRecentlyUsed(nullptr)
, fToBeDrawnCount(toBeDrawnCount)
{}
~BitmapInfo() {
SkASSERT(0 == fToBeDrawnCount);
delete fBitmap;
}
void addDraws(int drawsToAdd) {
if (0 == fToBeDrawnCount) {
// The readers will only ever decrement the count, so once the
// count is zero, the writer will be the only one modifying it,
// so it does not need to be an atomic operation.
fToBeDrawnCount = drawsToAdd;
} else {
sk_atomic_add(&fToBeDrawnCount, drawsToAdd);
}
}
void decDraws() {
sk_atomic_dec(&fToBeDrawnCount);
}
int drawCount() const {
return fToBeDrawnCount;
}
SkBitmap* fBitmap;
// Store the generation ID of the original bitmap, since copying does
// not copy this field, so fBitmap's generation ID will not be useful
// for comparing.
// FIXME: Is it reasonable to make copying a bitmap/pixelref copy the
// generation ID?
uint32_t fGenID;
// Keep track of the bytes allocated for this bitmap. When replacing the
// bitmap or removing this BitmapInfo we know how much memory has been
// reclaimed.
size_t fBytesAllocated;
// TODO: Generalize the LRU caching mechanism
BitmapInfo* fMoreRecentlyUsed;
BitmapInfo* fLessRecentlyUsed;
private:
int fToBeDrawnCount;
};
static inline bool shouldFlattenBitmaps(uint32_t flags) {
return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag
&& !(flags & SkGPipeWriter::kSharedAddressSpace_Flag));
}
class SkImageHeap : public SkRefCnt {
public:
SkImageHeap();
virtual ~SkImageHeap();
size_t bytesInCache() const { return fBytesInCache; }
void reset();
// slot must be "valid" -- 0 is never valid
const SkImage* get(int32_t slot) const;
// returns 0 if not found, else returns slot
int32_t find(const SkImage*) const;
// returns non-zero value for where the image was stored
int32_t insert(const SkImage*);
private:
SkTDArray<const SkImage*> fArray;
size_t fBytesInCache;
};
///////////////////////////////////////////////////////////////////////////////
enum PaintOps {
kReset_PaintOp, // no arg
kFlags_PaintOp, // arg inline
kColor_PaintOp, // arg 32
kFilterLevel_PaintOp, // arg inline
kStyle_PaintOp, // arg inline
kJoin_PaintOp, // arg inline
kCap_PaintOp, // arg inline
kWidth_PaintOp, // arg scalar
kMiter_PaintOp, // arg scalar
kEncoding_PaintOp, // arg inline - text
kHinting_PaintOp, // arg inline - text
kAlign_PaintOp, // arg inline - text
kTextSize_PaintOp, // arg scalar - text
kTextScaleX_PaintOp,// arg scalar - text
kTextSkewX_PaintOp, // arg scalar - text
kTypeface_PaintOp, // arg inline (index) - text
kFlatIndex_PaintOp, // flags=paintflat, data=index
};
#define PAINTOPS_OP_BITS 8
#define PAINTOPS_FLAG_BITS 4
#define PAINTOPS_DATA_BITS 20
#define PAINTOPS_OP_MASK ((1 << PAINTOPS_OP_BITS) - 1)
#define PAINTOPS_FLAG_MASK ((1 << PAINTOPS_FLAG_BITS) - 1)
#define PAINTOPS_DATA_MASK ((1 << PAINTOPS_DATA_BITS) - 1)
static inline unsigned PaintOp_unpackOp(uint32_t op32) {
return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
}
static inline unsigned PaintOp_unpackFlags(uint32_t op32) {
return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
}
static inline unsigned PaintOp_unpackData(uint32_t op32) {
return op32 & PAINTOPS_DATA_MASK;
}
static inline uint32_t PaintOp_packOp(PaintOps op) {
SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
}
static inline uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
}
static inline uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsigned data) {
SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
(flags << PAINTOPS_DATA_BITS) |
data;
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,115 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SamplePipeControllers.h"
#include "SkCanvas.h"
#include "SkGPipe.h"
#include "SkMatrix.h"
PipeController::PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc proc)
:fReader(target) {
fBlock = nullptr;
fBlockSize = fBytesWritten = 0;
fReader.setBitmapDecoder(proc);
}
PipeController::~PipeController() {
sk_free(fBlock);
}
void* PipeController::requestBlock(size_t minRequest, size_t *actual) {
sk_free(fBlock);
fBlockSize = minRequest;
fBlock = sk_malloc_throw(fBlockSize);
fBytesWritten = 0;
*actual = fBlockSize;
return fBlock;
}
void PipeController::notifyWritten(size_t bytes) {
fStatus = fReader.playback(this->getData(), bytes);
SkASSERT(SkGPipeReader::kError_Status != fStatus);
fBytesWritten += bytes;
}
////////////////////////////////////////////////////////////////////////////////
TiledPipeController::TiledPipeController(const SkBitmap& bitmap,
SkPicture::InstallPixelRefProc proc,
const SkMatrix* initial)
: INHERITED(nullptr, proc) {
int32_t top = 0;
int32_t bottom;
int32_t height = bitmap.height() / NumberOfTiles;
SkIRect rect;
for (int i = 0; i < NumberOfTiles; i++) {
bottom = i + 1 == NumberOfTiles ? bitmap.height() : top + height;
rect.setLTRB(0, top, bitmap.width(), bottom);
top = bottom;
SkDEBUGCODE(bool extracted = )bitmap.extractSubset(&fBitmaps[i], rect);
SkASSERT(extracted);
SkCanvas* canvas = new SkCanvas(fBitmaps[i]);
if (initial != nullptr) {
canvas->setMatrix(*initial);
}
canvas->translate(SkIntToScalar(-rect.left()),
SkIntToScalar(-rect.top()));
if (0 == i) {
fReader.setCanvas(canvas);
} else {
fReaders[i - 1].setCanvas(canvas);
fReaders[i - 1].setBitmapDecoder(proc);
}
canvas->unref();
}
}
void TiledPipeController::notifyWritten(size_t bytes) {
for (int i = 0; i < NumberOfTiles - 1; i++) {
fReaders[i].playback(this->getData(), bytes);
}
this->INHERITED::notifyWritten(bytes);
}
////////////////////////////////////////////////////////////////////////////////
ThreadSafePipeController::ThreadSafePipeController(int numberOfReaders)
: fAllocator(kMinBlockSize)
, fNumberOfReaders(numberOfReaders) {
fBlock = nullptr;
fBytesWritten = 0;
}
void* ThreadSafePipeController::requestBlock(size_t minRequest, size_t *actual) {
if (fBlock) {
// Save the previous block for later
PipeBlock previousBloc(fBlock, fBytesWritten);
fBlockList.push(previousBloc);
}
int32_t blockSize = SkMax32(SkToS32(minRequest), kMinBlockSize);
fBlock = fAllocator.allocThrow(blockSize);
fBytesWritten = 0;
*actual = blockSize;
return fBlock;
}
void ThreadSafePipeController::notifyWritten(size_t bytes) {
fBytesWritten += bytes;
}
void ThreadSafePipeController::draw(SkCanvas* target) {
SkGPipeReader reader(target);
for (int currentBlock = 0; currentBlock < fBlockList.count(); currentBlock++ ) {
reader.playback(fBlockList[currentBlock].fBlock, fBlockList[currentBlock].fBytes);
}
if (fBlock) {
reader.playback(fBlock, fBytesWritten);
}
}

View File

@ -1,87 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "SkChunkAlloc.h"
#include "SkGPipe.h"
#include "SkPicture.h"
#include "SkTDArray.h"
class SkCanvas;
class SkMatrix;
class PipeController : public SkGPipeController {
public:
PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc proc = nullptr);
virtual ~PipeController();
void* requestBlock(size_t minRequest, size_t* actual) override;
void notifyWritten(size_t bytes) override;
protected:
const void* getData() { return (const char*) fBlock + fBytesWritten; }
SkGPipeReader fReader;
private:
void* fBlock;
size_t fBlockSize;
size_t fBytesWritten;
SkGPipeReader::Status fStatus;
};
////////////////////////////////////////////////////////////////////////////////
class TiledPipeController : public PipeController {
public:
TiledPipeController(const SkBitmap&, SkPicture::InstallPixelRefProc proc = nullptr,
const SkMatrix* initialMatrix = nullptr);
virtual ~TiledPipeController() {};
void notifyWritten(size_t bytes) override;
int numberOfReaders() const override { return NumberOfTiles; }
private:
enum {
NumberOfTiles = 10
};
SkGPipeReader fReaders[NumberOfTiles - 1];
SkBitmap fBitmaps[NumberOfTiles];
typedef PipeController INHERITED;
};
////////////////////////////////////////////////////////////////////////////////
/**
* Borrowed (and modified) from SkDeferredCanvas.cpp::DeferredPipeController.
* Allows playing back from multiple threads, but does not do the threading itself.
*/
class ThreadSafePipeController : public SkGPipeController {
public:
ThreadSafePipeController(int numberOfReaders);
void* requestBlock(size_t minRequest, size_t* actual) override;
void notifyWritten(size_t bytes) override;
int numberOfReaders() const override { return fNumberOfReaders; }
/**
* Play the stored drawing commands to the specified canvas. If SkGPipeWriter::startRecording
* used the flag SkGPipeWriter::kSimultaneousReaders_Flag, this can be called from different
* threads simultaneously.
*/
void draw(SkCanvas*);
private:
enum {
kMinBlockSize = 4096
};
struct PipeBlock {
PipeBlock(void* block, size_t bytes) { fBlock = block, fBytes = bytes; }
// Stream of draw commands written by the SkGPipeWriter. Allocated by fAllocator, which will
// handle freeing it.
void* fBlock;
// Number of bytes that were written to fBlock.
size_t fBytes;
};
void* fBlock;
size_t fBytesWritten;
SkChunkAlloc fAllocator;
SkTDArray<PipeBlock> fBlockList;
int fNumberOfReaders;
};

View File

@ -1,56 +0,0 @@
/*
* Copyright 2012 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SamplePipeControllers.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkGPipe.h"
#include "SkPaint.h"
#include "SkShader.h"
#include "Test.h"
// Ensures that the pipe gracefully handles drawing an invalid bitmap.
static void testDrawingBadBitmap(SkCanvas* pipeCanvas) {
SkBitmap badBitmap;
badBitmap.setInfo(SkImageInfo::MakeUnknown(5, 5));
pipeCanvas->drawBitmap(badBitmap, 0, 0);
}
// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
// SkGPipeWriter.
static void testDrawingAfterEndRecording(SkCanvas* canvas) {
PipeController pc(canvas);
SkGPipeWriter writer;
SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag);
writer.endRecording();
SkBitmap bm;
bm.allocN32Pixels(2, 2);
bm.eraseColor(SK_ColorTRANSPARENT);
SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
SkShader::kClamp_TileMode);
SkPaint paint;
paint.setShader(shader)->unref();
pipeCanvas->drawPaint(paint);
pipeCanvas->drawBitmap(bm, 0, 0);
}
DEF_TEST(Pipe, reporter) {
SkBitmap bitmap;
bitmap.setInfo(SkImageInfo::MakeN32Premul(64, 64));
SkCanvas canvas(bitmap);
PipeController pipeController(&canvas);
SkGPipeWriter writer;
SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
testDrawingBadBitmap(pipeCanvas);
writer.endRecording();
testDrawingAfterEndRecording(&canvas);
}