Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: src/core/SkPictureImageGenerator.cpp

Issue 1301633002: Add subsets to SkImageGenerator and SkImageCacherator . (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix release-build warning Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkMatrix.h" 10 #include "SkMatrix.h"
11 #include "SkPaint.h" 11 #include "SkPaint.h"
12 #include "SkPicture.h" 12 #include "SkPicture.h"
13 #include "SkSurface.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 24 #if SK_SUPPORT_GPU
25 GrTexture* onGenerateTexture(GrContext*, SkImageUsageType) override; 25 GrTexture* onGenerateTexture(GrContext*, SkImageUsageType, const SkIRect*) o verride;
26 #endif 26 #endif
27 27
28 private: 28 private:
29 SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, c onst SkPaint*); 29 SkPictureImageGenerator(const SkISize&, const SkPicture*, const SkMatrix*, c onst SkPaint*);
30 30
31 SkAutoTUnref<const SkPicture> fPicture; 31 SkAutoTUnref<const SkPicture> fPicture;
32 SkMatrix fMatrix; 32 SkMatrix fMatrix;
33 SkTLazy<SkPaint> fPaint; 33 SkTLazy<SkPaint> fPaint;
34 34
35 typedef SkImageGenerator INHERITED; 35 typedef SkImageGenerator INHERITED;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk Picture* picture, 81 SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk Picture* picture,
82 const SkMatrix* matrix, const SkPaint* paint) { 82 const SkMatrix* matrix, const SkPaint* paint) {
83 return SkPictureImageGenerator::Create(size, picture, matrix, paint); 83 return SkPictureImageGenerator::Create(size, picture, matrix, paint);
84 } 84 }
85 85
86 //////////////////////////////////////////////////////////////////////////////// /////////////////// 86 //////////////////////////////////////////////////////////////////////////////// ///////////////////
87 87
88 #if SK_SUPPORT_GPU 88 #if SK_SUPPORT_GPU
89 #include "GrTexture.h" 89 #include "GrTexture.h"
90 90
91 GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsa geType usage) { 91 GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsa geType usage,
92 const SkIRect* subset) {
93 const SkImageInfo& info = this->getInfo();
94 SkImageInfo surfaceInfo = subset ? info.makeWH(subset->width(), subset->heig ht()) : info;
95
92 // 96 //
93 // TODO: respect the usage, by possibly creating a different (pow2) surface 97 // TODO: respect the usage, by possibly creating a different (pow2) surface
94 // 98 //
95 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, 99 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx,
96 SkSurface::kYes_B udgeted, 100 SkSurface::kYes_B udgeted,
97 this->getInfo())) ; 101 surfaceInfo));
98 if (!surface.get()) { 102 if (!surface.get()) {
99 return nullptr; 103 return nullptr;
100 } 104 }
105
106 SkMatrix matrix = fMatrix;
107 if (subset) {
108 matrix.postTranslate(-subset->x(), -subset->y());
109 }
101 surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this f or us? 110 surface->getCanvas()->clear(0); // does NewRenderTarget promise to do this f or us?
102 surface->getCanvas()->drawPicture(fPicture, &fMatrix, fPaint.getMaybeNull()) ; 111 surface->getCanvas()->drawPicture(fPicture, &matrix, fPaint.getMaybeNull());
103 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); 112 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
104 if (!image.get()) { 113 if (!image.get()) {
105 return nullptr; 114 return nullptr;
106 } 115 }
107 return SkSafeRef(image->getTexture()); 116 return SkSafeRef(image->getTexture());
108 } 117 }
109 #endif 118 #endif
OLDNEW
« src/core/SkImageCacherator.cpp ('K') | « src/core/SkImageGenerator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698