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

Side by Side Diff: src/image/SkImage_Generator.cpp

Issue 2462013003: Deferred image generator subsetting (Closed)
Patch Set: unlocked generator access comments Created 4 years, 1 month 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
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h"
11 #include "SkData.h" 10 #include "SkData.h"
12 #include "SkImageCacherator.h" 11 #include "SkImageCacherator.h"
13 #include "SkImagePriv.h" 12 #include "SkImagePriv.h"
14 #include "SkPixelRef.h" 13 #include "SkPixelRef.h"
15 #include "SkSurface.h"
16 14
17 class SkImage_Generator : public SkImage_Base { 15 class SkImage_Generator : public SkImage_Base {
18 public: 16 public:
19 SkImage_Generator(SkImageCacherator::Validator* validator) 17 SkImage_Generator(SkImageCacherator::Validator* validator)
20 : INHERITED(validator->fInfo.width(), validator->fInfo.height(), validat or->fUniqueID) 18 : INHERITED(validator->fInfo.width(), validator->fInfo.height(), validat or->fUniqueID)
21 , fCache(validator) 19 , fCache(validator)
22 {} 20 {}
23 21
24 virtual SkImageInfo onImageInfo() const override { 22 virtual SkImageInfo onImageInfo() const override {
25 return fCache.info(); 23 return fCache.info();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const { 73 bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
76 return fCache.lockAsBitmap(bitmap, this, chint); 74 return fCache.lockAsBitmap(bitmap, this, chint);
77 } 75 }
78 76
79 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params, 77 GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams & params,
80 SkSourceGammaTreatment gammaTreatment ) const { 78 SkSourceGammaTreatment gammaTreatment ) const {
81 return fCache.lockAsTexture(ctx, params, gammaTreatment, this); 79 return fCache.lockAsTexture(ctx, params, gammaTreatment, this);
82 } 80 }
83 81
84 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const { 82 sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
85 // TODO: make this lazy, by wrapping the subset inside a new generator or so mething 83 SkASSERT(fCache.info().bounds().contains(subset));
86 // For now, we do effectively what we did before, make it a raster 84 SkASSERT(fCache.info().bounds() != subset);
87 85
88 const SkImageInfo info = SkImageInfo::MakeN32(subset.width(), subset.height( ), 86 const SkIRect generatorSubset = subset.makeOffset(fCache.fOrigin.x(), fCache .fOrigin.y());
89 this->alphaType()); 87 SkImageCacherator::Validator validator(fCache.fSharedGenerator, &generatorSu bset);
90 auto surface(SkSurface::MakeRaster(info)); 88 return validator ? sk_sp<SkImage>(new SkImage_Generator(&validator)) : nullp tr;
91 if (!surface) {
92 return nullptr;
93 }
94 surface->getCanvas()->clear(0);
95 surface->getCanvas()->drawImage(this, SkIntToScalar(-subset.x()), SkIntToSca lar(-subset.y()),
96 nullptr);
97 return surface->makeImageSnapshot();
98 } 89 }
99 90
100 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI Rect* subset) { 91 sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkI Rect* subset) {
101 SkImageCacherator::Validator validator(generator, subset); 92 SkImageCacherator::Validator validator(SkImageCacherator::SharedGenerator::M ake(generator),
93 subset);
102 94
103 return validator ? sk_make_sp<SkImage_Generator>(&validator) : nullptr; 95 return validator ? sk_make_sp<SkImage_Generator>(&validator) : nullptr;
104 } 96 }
OLDNEW
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698