some catchup CL revisions

BUG=skia:

Review URL: https://codereview.chromium.org/1295593002
This commit is contained in:
reed 2015-08-13 14:06:46 -07:00 committed by Commit bot
parent 7e6d9c0326
commit 8f4fe37b1c
4 changed files with 18 additions and 12 deletions

View File

@ -128,10 +128,8 @@ protected:
SkMatrix matrix; SkMatrix matrix;
matrix.setTranslate(-100, -100); matrix.setTranslate(-100, -100);
fCache.reset(new SkImageCacherator(SkImageGenerator::NewFromPicture(size, auto gen = SkImageGenerator::NewFromPicture(size, fPicture, &matrix, nullptr);
fPicture, fCache.reset(SkImageCacherator::NewFromGenerator(gen));
&matrix,
nullptr)));
} }
void drawSet(SkCanvas* canvas) const { void drawSet(SkCanvas* canvas) const {

View File

@ -144,9 +144,9 @@ public:
* Regarding the SkImageUsageType parameter: * Regarding the SkImageUsageType parameter:
* *
* If the context (the provided one or the generator's intrinsic one) determines that to * If the context (the provided one or the generator's intrinsic one) determines that to
* support the specified usage, it must return a different sized texture (from the generator's * support the specified usage, it must return a different sized texture it may,
* native size) it may, so the caller must inspect the texture's width/height * so the caller must inspect the texture's width/height and compare them to the generator's
* (unless kUntiled_SkImageUsedType was specified). * getInfo() width/height.
*/ */
GrTexture* generateTexture(GrContext*, SkImageUsageType); GrTexture* generateTexture(GrContext*, SkImageUsageType);

View File

@ -19,10 +19,17 @@
#include "SkGrPriv.h" #include "SkGrPriv.h"
#endif #endif
SkImageCacherator* SkImageCacherator::NewFromGenerator(SkImageGenerator* gen) {
if (!gen) {
return nullptr;
}
return SkNEW_ARGS(SkImageCacherator, (gen));
}
SkImageCacherator::SkImageCacherator(SkImageGenerator* gen) : fGenerator(gen) {} SkImageCacherator::SkImageCacherator(SkImageGenerator* gen) : fGenerator(gen) {}
SkImageCacherator::~SkImageCacherator() { SkImageCacherator::~SkImageCacherator() {
delete fGenerator; SkDELETE(fGenerator);
} }
static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) { static bool check_output_bitmap(const SkBitmap& bitmap, uint32_t expectedID) {

View File

@ -19,7 +19,8 @@ class SkBitmap;
class SkImageCacherator { class SkImageCacherator {
public: public:
// Takes ownership of the generator // Takes ownership of the generator
SkImageCacherator(SkImageGenerator* gen); static SkImageCacherator* NewFromGenerator(SkImageGenerator*);
~SkImageCacherator(); ~SkImageCacherator();
const SkImageInfo& info() const { return fGenerator->getInfo(); } const SkImageInfo& info() const { return fGenerator->getInfo(); }
@ -28,8 +29,6 @@ public:
/** /**
* On success (true), bitmap will point to the pixels for this generator. If this returns * On success (true), bitmap will point to the pixels for this generator. If this returns
* false, the bitmap will be reset to empty. * false, the bitmap will be reset to empty.
*
* The cached bitmap is valid until it goes out of scope.
*/ */
bool lockAsBitmap(SkBitmap*); bool lockAsBitmap(SkBitmap*);
@ -37,11 +36,13 @@ public:
* Returns a ref() on the texture produced by this generator. The caller must call unref() * Returns a ref() on the texture produced by this generator. The caller must call unref()
* when it is done. Will return NULL on failure. * when it is done. Will return NULL on failure.
* *
* The cached texture is valid until it is unref'd. * The caller is responsible for calling texture->unref() when they are done.
*/ */
GrTexture* lockAsTexture(GrContext*, SkImageUsageType); GrTexture* lockAsTexture(GrContext*, SkImageUsageType);
private: private:
SkImageCacherator(SkImageGenerator* gen);
bool tryLockAsBitmap(SkBitmap*); bool tryLockAsBitmap(SkBitmap*);
GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType); GrTexture* tryLockAsTexture(GrContext*, SkImageUsageType);