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