OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkImageGenerator.h" | 8 #include "SkImageGenerator.h" |
9 | |
10 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
11 #include "SkMatrix.h" | 10 #include "SkMatrix.h" |
12 #include "SkPaint.h" | 11 #include "SkPaint.h" |
13 #include "SkPicture.h" | 12 #include "SkPicture.h" |
| 13 #include "SkSurface.h" |
14 #include "SkTLazy.h" | 14 #include "SkTLazy.h" |
15 | 15 |
16 class SkPictureImageGenerator : SkImageGenerator { | 16 class SkPictureImageGenerator : SkImageGenerator { |
17 public: | 17 public: |
18 static SkImageGenerator* Create(const SkISize&, const SkPicture*, const SkMa
trix*, | 18 static SkImageGenerator* Create(const SkISize&, const SkPicture*, const SkMa
trix*, |
19 const SkPaint*); | 19 const SkPaint*); |
20 | 20 |
21 protected: | 21 protected: |
22 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkP
MColor ctable[], | 22 bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkP
MColor ctable[], |
23 int* ctableCount) override; | 23 int* ctableCount) override; |
| 24 #if SK_SUPPORT_GPU |
| 25 GrTexture* onGenerateTexture(GrContext*, SkImageUsageType) override; |
| 26 #endif |
24 | 27 |
25 private: | 28 private: |
26 SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, c
onst SkPaint*); | 29 SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, c
onst SkPaint*); |
27 | 30 |
28 SkAutoTUnref<const SkPicture> fPicture; | 31 SkAutoTUnref<const SkPicture> fPicture; |
29 SkMatrix fMatrix; | 32 SkMatrix fMatrix; |
30 SkTLazy<SkPaint> fPaint; | 33 SkTLazy<SkPaint> fPaint; |
31 | 34 |
32 typedef SkImageGenerator INHERITED; | 35 typedef SkImageGenerator INHERITED; |
33 }; | 36 }; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); | 75 SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); |
73 canvas.drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()); | 76 canvas.drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()); |
74 | 77 |
75 return true; | 78 return true; |
76 } | 79 } |
77 | 80 |
78 SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk
Picture* picture, | 81 SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk
Picture* picture, |
79 const SkMatrix* matrix, const
SkPaint* paint) { | 82 const SkMatrix* matrix, const
SkPaint* paint) { |
80 return SkPictureImageGenerator::Create(size, picture, matrix, paint); | 83 return SkPictureImageGenerator::Create(size, picture, matrix, paint); |
81 } | 84 } |
| 85 |
| 86 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 87 |
| 88 #if SK_SUPPORT_GPU |
| 89 #include "GrTexture.h" |
| 90 |
| 91 GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsa
geType usage) { |
| 92 // |
| 93 // TODO: respect the usage, by possibly creating a different (pow2) surface |
| 94 // |
| 95 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, |
| 96 SkSurface::kYes_B
udgeted, |
| 97 this->getInfo()))
; |
| 98 if (!surface.get()) { |
| 99 return nullptr; |
| 100 } |
| 101 surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this f
or us? |
| 102 surface->getCanvas()->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull())
; |
| 103 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 104 if (!image.get()) { |
| 105 return nullptr; |
| 106 } |
| 107 return SkSafeRef(image->getTexture()); |
| 108 } |
| 109 #endif |
OLD | NEW |