Skia
2D Graphics Library
SkDrawable.h
Go to the documentation of this file.
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 SkDrawable_DEFINED
9 #define SkDrawable_DEFINED
10 
13 #include "include/core/SkScalar.h"
14 
16 class SkCanvas;
17 class SkMatrix;
18 class SkPicture;
19 enum class GrBackendApi : unsigned;
20 struct SkRect;
21 
30 public:
36  void draw(SkCanvas*, const SkMatrix* = nullptr);
38 
69  public:
70  virtual ~GpuDrawHandler() {}
71 
72  virtual void draw(const GrBackendDrawableInfo&) {}
73  };
74 
81  std::unique_ptr<GpuDrawHandler> snapGpuDrawHandler(GrBackendApi backendApi,
82  const SkMatrix& matrix,
83  const SkIRect& clipBounds,
84  const SkImageInfo& bufferInfo) {
85  return this->onSnapGpuDrawHandler(backendApi, matrix, clipBounds, bufferInfo);
86  }
87 
89 
97  uint32_t getGenerationID();
98 
105 
112 
114  return kSkDrawable_Type;
115  }
116 
118  return kSkDrawable_Type;
119  }
120 
121  static sk_sp<SkDrawable> Deserialize(const void* data, size_t size,
122  const SkDeserialProcs* procs = nullptr) {
123  return sk_sp<SkDrawable>(static_cast<SkDrawable*>(
125  kSkDrawable_Type, data, size, procs).release()));
126  }
127 
128  Factory getFactory() const override { return nullptr; }
129  const char* getTypeName() const override { return nullptr; }
130 
131 protected:
133 
134  virtual SkRect onGetBounds() = 0;
135  virtual void onDraw(SkCanvas*) = 0;
136 
137  virtual std::unique_ptr<GpuDrawHandler> onSnapGpuDrawHandler(GrBackendApi, const SkMatrix&,
138  const SkIRect& /*clipBounds*/,
139  const SkImageInfo&) {
140  return nullptr;
141  }
142 
143  // TODO: Delete this once Android gets updated to take the clipBounds version above.
144  virtual std::unique_ptr<GpuDrawHandler> onSnapGpuDrawHandler(GrBackendApi, const SkMatrix&) {
145  return nullptr;
146  }
147 
155 
156 private:
157  int32_t fGenerationID;
158 };
159 
160 #endif
SkFlattenable.h
SkDrawable::getFactory
Factory getFactory() const override
Implement this to return a factory function pointer that can be called to recreate your class given a...
Definition: SkDrawable.h:128
SkDrawable::GpuDrawHandler::draw
virtual void draw(const GrBackendDrawableInfo &)
Definition: SkDrawable.h:72
SkDrawable::getTypeName
const char * getTypeName() const override
Returns the name of the object's class.
Definition: SkDrawable.h:129
SkDrawable::draw
void draw(SkCanvas *, const SkMatrix *=nullptr)
Draws into the specified content.
SkFlattenable::Deserialize
static sk_sp< SkFlattenable > Deserialize(Type, const void *data, size_t length, const SkDeserialProcs *procs=nullptr)
SkDrawable::Deserialize
static sk_sp< SkDrawable > Deserialize(const void *data, size_t size, const SkDeserialProcs *procs=nullptr)
Definition: SkDrawable.h:121
SkDrawable::SkDrawable
SkDrawable()
SkDrawable::onNewPictureSnapshot
virtual SkPicture * onNewPictureSnapshot()
Default implementation calls onDraw() with a canvas that records into a picture.
SkFlattenable::Type
Type
Definition: SkFlattenable.h:28
SkDrawable::onSnapGpuDrawHandler
virtual std::unique_ptr< GpuDrawHandler > onSnapGpuDrawHandler(GrBackendApi, const SkMatrix &)
Definition: SkDrawable.h:144
SkDrawable::getBounds
SkRect getBounds()
Return the (conservative) bounds of what the drawable will draw.
SkDrawable::onDraw
virtual void onDraw(SkCanvas *)=0
SkScalar.h
sk_sp
Shared pointer class to wrap classes that support a ref()/unref() interface.
Definition: SkRefCnt.h:215
SkDrawable::getGenerationID
uint32_t getGenerationID()
Return a unique value for this instance.
SK_API
#define SK_API
Definition: SkTypes.h:181
SkImageInfo
Definition: SkImageInfo.h:283
SkDrawable::onGetBounds
virtual SkRect onGetBounds()=0
SkFlattenable::kSkDrawable_Type
@ kSkDrawable_Type
Definition: SkFlattenable.h:30
SkCanvas
Definition: SkCanvas.h:87
SkPicture
Definition: SkPicture.h:39
SkDrawable
Base-class for objects that draw into SkCanvas.
Definition: SkDrawable.h:29
SkDrawable::getFlattenableType
SkFlattenable::Type getFlattenableType() const override
Definition: SkDrawable.h:117
GrBackendDrawableInfo
Definition: GrBackendDrawableInfo.h:15
SkScalar
float SkScalar
Definition: SkScalar.h:16
GrBackendApi
GrBackendApi
Possible 3D APIs that may be used by Ganesh.
Definition: GrTypes.h:135
SkDrawable::newPictureSnapshot
SkPicture * newPictureSnapshot()
SkDrawable::snapGpuDrawHandler
std::unique_ptr< GpuDrawHandler > snapGpuDrawHandler(GrBackendApi backendApi, const SkMatrix &matrix, const SkIRect &clipBounds, const SkImageInfo &bufferInfo)
Snaps off a GpuDrawHandler to represent the state of the SkDrawable at the time the snap is called.
Definition: SkDrawable.h:81
SkMatrix
Definition: SkMatrix.h:48
SkIRect
Definition: SkRect.h:28
SkDrawable::notifyDrawingChanged
void notifyDrawingChanged()
Calling this invalidates the previous generation ID, and causes a new one to be computed the next tim...
SkDrawable::GpuDrawHandler
When using the GPU backend it is possible for a drawable to execute using the underlying 3D API rathe...
Definition: SkDrawable.h:68
SkDrawable::GetFlattenableType
static SkFlattenable::Type GetFlattenableType()
Definition: SkDrawable.h:113
SkDrawable::draw
void draw(SkCanvas *, SkScalar x, SkScalar y)
SkRect
Definition: SkRect.h:572
SkDeserialProcs
Definition: SkSerialProcs.h:61
SkDrawable::onSnapGpuDrawHandler
virtual std::unique_ptr< GpuDrawHandler > onSnapGpuDrawHandler(GrBackendApi, const SkMatrix &, const SkIRect &, const SkImageInfo &)
Definition: SkDrawable.h:137
SkFlattenable
Definition: SkFlattenable.h:26
SkImageInfo.h
SkDrawable::GpuDrawHandler::~GpuDrawHandler
virtual ~GpuDrawHandler()
Definition: SkDrawable.h:70