Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2014 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkPictureRecorder_DEFINED
      9 #define SkPictureRecorder_DEFINED
     10 
     11 #include "SkBBHFactory.h"
     12 #include "SkPicture.h"
     13 #include "SkRefCnt.h"
     14 
     15 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
     16 namespace android {
     17     class Picture;
     18 };
     19 #endif
     20 
     21 class SkCanvas;
     22 class SkPictureRecord;
     23 class SkRecord;
     24 class SkRecorder;
     25 
     26 class SK_API SkPictureRecorder : SkNoncopyable {
     27 public:
     28     SkPictureRecorder();
     29     ~SkPictureRecorder();
     30 
     31 #ifdef SK_LEGACY_PICTURE_SIZE_API
     32     SkCanvas* beginRecording(int width, int height,
     33                              SkBBHFactory* bbhFactory = NULL,
     34                              uint32_t recordFlags = 0) {
     35         return this->beginRecording(SkIntToScalar(width), SkIntToScalar(height),
     36                                     bbhFactory, recordFlags);
     37     }
     38 #endif
     39 
     40     /** Returns the canvas that records the drawing commands.
     41         @param width the width of the cull rect used when recording this picture.
     42         @param height the height of the cull rect used when recording this picture.
     43         @param bbhFactory factory to create desired acceleration structure
     44         @param recordFlags optional flags that control recording.
     45         @return the canvas.
     46     */
     47     SkCanvas* beginRecording(SkScalar width, SkScalar height,
     48                              SkBBHFactory* bbhFactory = NULL,
     49                              uint32_t recordFlags = 0);
     50 
     51     // As usual, we have a deprecated old version and a maybe almost working
     52     // new version.  We currently point beginRecording() to
     53     // DEPRECATED_beginRecording() unless SK_PICTURE_USE_SK_RECORD is defined,
     54     // then we use EXPERIMENTAL_beginRecording().
     55 
     56     // Old slower backend.
     57     SkCanvas* DEPRECATED_beginRecording(SkScalar width, SkScalar height,
     58                                         SkBBHFactory* bbhFactory = NULL,
     59                                         uint32_t recordFlags = 0);
     60 
     61     // New faster backend.
     62     SkCanvas* EXPERIMENTAL_beginRecording(SkScalar width, SkScalar height,
     63                                           SkBBHFactory* bbhFactory = NULL);
     64 
     65     /** Returns the recording canvas if one is active, or NULL if recording is
     66         not active. This does not alter the refcnt on the canvas (if present).
     67     */
     68     SkCanvas* getRecordingCanvas();
     69 
     70     /** Signal that the caller is done recording. This invalidates the canvas
     71         returned by beginRecording/getRecordingCanvas, and returns the
     72         created SkPicture. Note that the returned picture has its creation
     73         ref which the caller must take ownership of.
     74     */
     75     SkPicture* endRecording();
     76 
     77     /** Enable/disable all the picture recording optimizations (i.e.,
     78         those in SkPictureRecord). It is mainly intended for testing the
     79         existing optimizations (i.e., to actually have the pattern
     80         appear in an .skp we have to disable the optimization). Call right
     81         after 'beginRecording'.
     82     */
     83     void internalOnly_EnableOpts(bool enableOpts);
     84 
     85 private:
     86     void reset();
     87 
     88     /** Replay the current (partially recorded) operation stream into
     89         canvas. This call doesn't close the current recording.
     90     */
     91 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
     92     friend class android::Picture;
     93 #endif
     94     friend class SkPictureRecorderReplayTester; // for unit testing
     95     void partialReplay(SkCanvas* canvas) const;
     96 
     97     SkScalar                      fCullWidth;
     98     SkScalar                      fCullHeight;
     99     SkAutoTUnref<SkBBoxHierarchy> fBBH;
    100 
    101     // One of these two canvases will be non-NULL.
    102     SkAutoTUnref<SkPictureRecord> fPictureRecord;  // beginRecording()
    103     SkAutoTUnref<SkRecorder>      fRecorder;       // EXPERIMENTAL_beginRecording()
    104 
    105     // Used by EXPERIMENTAL_beginRecording().
    106     SkAutoTDelete<SkRecord> fRecord;
    107 
    108     typedef SkNoncopyable INHERITED;
    109 };
    110 
    111 #endif
    112