1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC. 2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. 3cb93a386Sopenharmony_ci#ifndef SkPDFGraphicStackState_DEFINED 4cb93a386Sopenharmony_ci#define SkPDFGraphicStackState_DEFINED 5cb93a386Sopenharmony_ci 6cb93a386Sopenharmony_ci#include "include/core/SkColor.h" 7cb93a386Sopenharmony_ci#include "include/core/SkMatrix.h" 8cb93a386Sopenharmony_ci#include "include/core/SkScalar.h" 9cb93a386Sopenharmony_ci#include "src/core/SkClipStack.h" 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ciclass SkDynamicMemoryWStream; 12cb93a386Sopenharmony_ci 13cb93a386Sopenharmony_ci// It is important to not confuse SkPDFGraphicStackState with SkPDFGraphicState, the 14cb93a386Sopenharmony_ci// later being our representation of an object in the PDF file. 15cb93a386Sopenharmony_cistruct SkPDFGraphicStackState { 16cb93a386Sopenharmony_ci struct Entry { 17cb93a386Sopenharmony_ci SkMatrix fMatrix = SkMatrix::I(); 18cb93a386Sopenharmony_ci uint32_t fClipStackGenID = SkClipStack::kWideOpenGenID; 19cb93a386Sopenharmony_ci SkColor4f fColor = {0, 0, 0, 1}; 20cb93a386Sopenharmony_ci SkScalar fTextScaleX = 1; // Zero means we don't care what the value is. 21cb93a386Sopenharmony_ci int fShaderIndex = -1; 22cb93a386Sopenharmony_ci int fGraphicStateIndex = -1; 23cb93a386Sopenharmony_ci }; 24cb93a386Sopenharmony_ci // Must use stack for matrix, and for clip, plus one for no matrix or clip. 25cb93a386Sopenharmony_ci inline static constexpr int kMaxStackDepth = 2; 26cb93a386Sopenharmony_ci Entry fEntries[kMaxStackDepth + 1]; 27cb93a386Sopenharmony_ci int fStackDepth = 0; 28cb93a386Sopenharmony_ci SkDynamicMemoryWStream* fContentStream; 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ci SkPDFGraphicStackState(SkDynamicMemoryWStream* s = nullptr) : fContentStream(s) {} 31cb93a386Sopenharmony_ci void updateClip(const SkClipStack* clipStack, const SkIRect& bounds); 32cb93a386Sopenharmony_ci void updateMatrix(const SkMatrix& matrix); 33cb93a386Sopenharmony_ci void updateDrawingState(const Entry& state); 34cb93a386Sopenharmony_ci void push(); 35cb93a386Sopenharmony_ci void pop(); 36cb93a386Sopenharmony_ci void drainStack(); 37cb93a386Sopenharmony_ci Entry* currentEntry() { return &fEntries[fStackDepth]; } 38cb93a386Sopenharmony_ci}; 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_ci#endif // SkPDFGraphicStackState_DEFINED 41