| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_PAINT_PAINT_SURFACE_H_ | |
| 6 #define CC_PAINT_PAINT_SURFACE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "base/optional.h" | |
| 11 #include "cc/paint/paint_export.h" | |
| 12 #include "cc/paint/skia_paint_canvas.h" | |
| 13 #include "third_party/skia/include/core/SkSurface.h" | |
| 14 | |
| 15 namespace cc { | |
| 16 | |
| 17 class CC_PAINT_EXPORT PaintSurface : public SkRefCntBase { | |
| 18 public: | |
| 19 explicit PaintSurface(sk_sp<SkSurface> surface); | |
| 20 ~PaintSurface() override; | |
| 21 | |
| 22 // TODO(enne): this interface matches SkSurface for simplicity. | |
| 23 // However, this should really be changed to make the SkSurface ctor | |
| 24 // public and have that be the only constructor. This will also | |
| 25 // clean up a bunch of code where there's an SkSurface and a PaintCanvas, | |
| 26 // such as for canvas in Blink. | |
| 27 static sk_sp<PaintSurface> MakeRaster(const SkImageInfo& info, | |
| 28 const SkSurfaceProps* props = nullptr) { | |
| 29 sk_sp<SkSurface> s = SkSurface::MakeRaster(info, props); | |
| 30 return sk_make_sp<PaintSurface>(std::move(s)); | |
| 31 } | |
| 32 static sk_sp<PaintSurface> MakeRasterN32Premul( | |
| 33 int width, | |
| 34 int height, | |
| 35 const SkSurfaceProps* props = nullptr) { | |
| 36 sk_sp<SkSurface> s = SkSurface::MakeRasterN32Premul(width, height, props); | |
| 37 return sk_make_sp<PaintSurface>(std::move(s)); | |
| 38 } | |
| 39 | |
| 40 int width() const { return surface_->width(); } | |
| 41 int height() const { return surface_->height(); } | |
| 42 | |
| 43 PaintCanvas* getCanvas() { | |
| 44 if (!canvas_.has_value()) | |
| 45 canvas_.emplace(surface_->getCanvas()); | |
| 46 return &canvas_.value(); | |
| 47 } | |
| 48 | |
| 49 private: | |
| 50 const sk_sp<SkSurface> surface_; | |
| 51 base::Optional<SkiaPaintCanvas> canvas_; | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(PaintSurface); | |
| 54 }; | |
| 55 | |
| 56 } // namespace cc | |
| 57 | |
| 58 #endif // CC_PAINT_PAINT_SURFACE_H_ | |
| OLD | NEW |