18ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org/*
28ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org * Copyright 2014 Google Inc.
38ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org *
48ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be
58ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org * found in the LICENSE file.
68ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org */
78ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
882365915476caedc130d0e36012a1ce0c007c4aerobertphillips#ifndef SkLayerInfo_DEFINED
982365915476caedc130d0e36012a1ce0c007c4aerobertphillips#define SkLayerInfo_DEFINED
108ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
119db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein#include "SkBigPicture.h"
1230d2cc6ff47cb7f981d83e9a536971beec920f61robertphillips#include "SkTArray.h"
138ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
1482365915476caedc130d0e36012a1ce0c007c4aerobertphillips// This class stores information about the saveLayer/restore pairs found
1582365915476caedc130d0e36012a1ce0c007c4aerobertphillips// within an SkPicture. It is used by Ganesh to perform layer hoisting.
169db912c2ac2ab53bc24f2d50a3e5a80162051dccmtkleinclass SkLayerInfo : public SkBigPicture::AccelData {
178ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.orgpublic:
1882365915476caedc130d0e36012a1ce0c007c4aerobertphillips    // Information about a given saveLayer/restore block in an SkPicture
1982365915476caedc130d0e36012a1ce0c007c4aerobertphillips    class BlockInfo {
2030d2cc6ff47cb7f981d83e9a536971beec920f61robertphillips    public:
212880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        BlockInfo() : fPicture(nullptr), fPaint(nullptr), fKey(nullptr), fKeySize(0) {}
222880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        ~BlockInfo() {
232880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            SkSafeUnref(fPicture);
242880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            delete fPaint;
252880df2609eba09b555ca37be04b6ad89290c765Tom Hudson            delete[] fKey;
262880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        }
2730d2cc6ff47cb7f981d83e9a536971beec920f61robertphillips
2830d2cc6ff47cb7f981d83e9a536971beec920f61robertphillips        // The picture owning the layer. If the owning picture is the top-most
2982365915476caedc130d0e36012a1ce0c007c4aerobertphillips        // one (i.e., the picture for which this SkLayerInfo was created) then
302880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        // this pointer is nullptr. If it is a nested picture then the pointer
312880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        // is non-nullptr and owns a ref on the picture.
3230d2cc6ff47cb7f981d83e9a536971beec920f61robertphillips        const SkPicture* fPicture;
333aac6e0848010efe046bd86bcb341dad5a23e174robertphillips        // The device space bounds of this layer.
34d8aa7b74c8ef0cb8ed3f6b03beb7ee5013624372robertphillips        SkRect fBounds;
35478dd723362fefc2023aee03e11216d913eeac03robertphillips        // If not-empty, the optional bounds parameter passed in to the saveLayer
36478dd723362fefc2023aee03e11216d913eeac03robertphillips        // call.
37478dd723362fefc2023aee03e11216d913eeac03robertphillips        SkRect fSrcBounds;
389e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // The pre-matrix begins as the identity and accumulates the transforms
399e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // of the containing SkPictures (if any). This matrix state has to be
409db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein        // part of the initial matrix during replay so that it will be
419e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // preserved across setMatrix calls.
429e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        SkMatrix fPreMat;
439db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein        // The matrix state (in the leaf picture) in which this layer's draws
449e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // must occur. It will/can be overridden by setMatrix calls in the
459db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein        // layer itself. It does not include the translation needed to map the
469e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // layer's top-left point to the origin (which must be part of the
479e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        // initial matrix).
489e6835da41e344ef3c4c35036fabfdb0a4146c33robertphillips        SkMatrix fLocalMat;
492880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        // The paint to use on restore. Can be nullptr since it is optional.
500205aba7d5e8802d2a3ef55d999f5aa41db3adc9commit-bot@chromium.org        const SkPaint* fPaint;
5182365915476caedc130d0e36012a1ce0c007c4aerobertphillips        // The index of this saveLayer in the picture.
528ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org        size_t  fSaveLayerOpID;
5382365915476caedc130d0e36012a1ce0c007c4aerobertphillips        // The index of the matching restore in the picture.
548ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org        size_t  fRestoreOpID;
558ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org        // True if this saveLayer has at least one other saveLayer nested within it.
568ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org        // False otherwise.
578ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org        bool    fHasNestedLayers;
580205aba7d5e8802d2a3ef55d999f5aa41db3adc9commit-bot@chromium.org        // True if this saveLayer is nested within another. False otherwise.
590205aba7d5e8802d2a3ef55d999f5aa41db3adc9commit-bot@chromium.org        bool    fIsNested;
6001d6e5f462d1d52203ee1a6660415877e4cf2dderobertphillips        // The variable length key for this saveLayer block. It stores the
6101d6e5f462d1d52203ee1a6660415877e4cf2dderobertphillips        // thread of drawPicture and saveLayer operation indices that lead to this
6201d6e5f462d1d52203ee1a6660415877e4cf2dderobertphillips        // saveLayer (including its own op index). The BlockInfo owns this memory.
632880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        int* fKey;
642880df2609eba09b555ca37be04b6ad89290c765Tom Hudson        int  fKeySize;  // # of ints
658ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org    };
668ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
679db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein    SkLayerInfo() {}
688ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
6982365915476caedc130d0e36012a1ce0c007c4aerobertphillips    BlockInfo& addBlock() { return fBlocks.push_back(); }
708fd9382c25804d8e4e296c11ae7c63ed2d2691d5commit-bot@chromium.org
7182365915476caedc130d0e36012a1ce0c007c4aerobertphillips    int numBlocks() const { return fBlocks.count(); }
728ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
7382365915476caedc130d0e36012a1ce0c007c4aerobertphillips    const BlockInfo& block(int index) const {
7482365915476caedc130d0e36012a1ce0c007c4aerobertphillips        SkASSERT(index < fBlocks.count());
758ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
7682365915476caedc130d0e36012a1ce0c007c4aerobertphillips        return fBlocks[index];
778ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org    }
788ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
79beb1af2f34b5c538fc08d849b132355160b4c93frobertphillips@google.comprivate:
8082365915476caedc130d0e36012a1ce0c007c4aerobertphillips    SkTArray<BlockInfo, true> fBlocks;
818ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
829db912c2ac2ab53bc24f2d50a3e5a80162051dccmtklein    typedef SkBigPicture::AccelData INHERITED;
838ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org};
848ddc26b68c4e41199c06961da3bff2ce72afff14commit-bot@chromium.org
8582365915476caedc130d0e36012a1ce0c007c4aerobertphillips#endif // SkLayerInfo_DEFINED
86