gfx/skia/trunk/src/pipe/utils/SamplePipeControllers.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/pipe/utils/SamplePipeControllers.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/*
     1.5 + * Copyright 2012 Google Inc.
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#include "SkBitmap.h"
    1.12 +#include "SkChunkAlloc.h"
    1.13 +#include "SkGPipe.h"
    1.14 +#include "SkPicture.h"
    1.15 +#include "SkTDArray.h"
    1.16 +
    1.17 +class SkCanvas;
    1.18 +class SkMatrix;
    1.19 +
    1.20 +class PipeController : public SkGPipeController {
    1.21 +public:
    1.22 +    PipeController(SkCanvas* target, SkPicture::InstallPixelRefProc proc = NULL);
    1.23 +    virtual ~PipeController();
    1.24 +    virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE;
    1.25 +    virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
    1.26 +protected:
    1.27 +    const void* getData() { return (const char*) fBlock + fBytesWritten; }
    1.28 +    SkGPipeReader fReader;
    1.29 +private:
    1.30 +    void* fBlock;
    1.31 +    size_t fBlockSize;
    1.32 +    size_t fBytesWritten;
    1.33 +    SkGPipeReader::Status fStatus;
    1.34 +};
    1.35 +
    1.36 +////////////////////////////////////////////////////////////////////////////////
    1.37 +
    1.38 +class TiledPipeController : public PipeController {
    1.39 +public:
    1.40 +    TiledPipeController(const SkBitmap&, SkPicture::InstallPixelRefProc proc = NULL,
    1.41 +                        const SkMatrix* initialMatrix = NULL);
    1.42 +    virtual ~TiledPipeController() {};
    1.43 +    virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
    1.44 +    virtual int numberOfReaders() const SK_OVERRIDE { return NumberOfTiles; }
    1.45 +private:
    1.46 +    enum {
    1.47 +        NumberOfTiles = 10
    1.48 +    };
    1.49 +    SkGPipeReader fReaders[NumberOfTiles - 1];
    1.50 +    SkBitmap fBitmaps[NumberOfTiles];
    1.51 +    typedef PipeController INHERITED;
    1.52 +};
    1.53 +
    1.54 +////////////////////////////////////////////////////////////////////////////////
    1.55 +
    1.56 +/**
    1.57 + * Borrowed (and modified) from SkDeferredCanvas.cpp::DeferredPipeController.
    1.58 + * Allows playing back from multiple threads, but does not do the threading itself.
    1.59 + */
    1.60 +class ThreadSafePipeController : public SkGPipeController {
    1.61 +public:
    1.62 +    ThreadSafePipeController(int numberOfReaders);
    1.63 +    virtual void* requestBlock(size_t minRequest, size_t* actual) SK_OVERRIDE;
    1.64 +    virtual void notifyWritten(size_t bytes) SK_OVERRIDE;
    1.65 +    virtual int numberOfReaders() const SK_OVERRIDE { return fNumberOfReaders; }
    1.66 +
    1.67 +    /**
    1.68 +     * Play the stored drawing commands to the specified canvas. If SkGPipeWriter::startRecording
    1.69 +     * used the flag SkGPipeWriter::kSimultaneousReaders_Flag, this can be called from different
    1.70 +     * threads simultaneously.
    1.71 +     */
    1.72 +    void draw(SkCanvas*);
    1.73 +private:
    1.74 +    enum {
    1.75 +        kMinBlockSize = 4096
    1.76 +    };
    1.77 +    struct PipeBlock {
    1.78 +        PipeBlock(void* block, size_t bytes) { fBlock = block, fBytes = bytes; }
    1.79 +        // Stream of draw commands written by the SkGPipeWriter. Allocated by fAllocator, which will
    1.80 +        // handle freeing it.
    1.81 +        void* fBlock;
    1.82 +        // Number of bytes that were written to fBlock.
    1.83 +        size_t fBytes;
    1.84 +    };
    1.85 +    void* fBlock;
    1.86 +    size_t fBytesWritten;
    1.87 +    SkChunkAlloc fAllocator;
    1.88 +    SkTDArray<PipeBlock> fBlockList;
    1.89 +    int fNumberOfReaders;
    1.90 +};

mercurial