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

Side by Side Diff: src/lazy/SkLazyCachingPixelRef.cpp

Issue 54203006: Break up SkLazyPixelRef functionally into class hierarchy. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: lint nits Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Sk64.h"
9 #include "SkColorTable.h"
10 #include "SkData.h"
11 #include "SkImageDecoder.h"
12 #include "SkImagePriv.h"
13 #include "SkLazyCachingPixelRef.h"
14 #include "SkScaledImageCache.h"
15 #include "SkPostConfig.h"
16
17 SkLazyCachingPixelRef::SkLazyCachingPixelRef(SkData* data,
18 SkBitmapFactory::DecodeProc proc,
19 SkScaledImageCache* cache)
20 : INHERITED(cache)
21 , fDecodeProc(proc) {
22 if (NULL == data) {
23 fData = SkData::NewEmpty();
24 } else {
25 fData = data;
26 fData->ref();
27 }
28 memset(&fLazilyCachedInfo, 0xFF, sizeof(fLazilyCachedInfo));
29
30 if (NULL == fDecodeProc) { // use a reasonable default.
31 fDecodeProc = SkImageDecoder::DecodeMemoryToTarget;
32 }
33 this->setImmutable();
34 }
35
36 SkLazyCachingPixelRef::~SkLazyCachingPixelRef() {
37 SkASSERT(fData != NULL);
38 fData->unref();
39 }
40
41 bool SkLazyCachingPixelRef::onDecodeInfo(SkISize* size,
42 SkBitmap::Config* config,
43 SkAlphaType* alphaType) {
44 SkASSERT(size && config &&alphaType);
45 if (fLazilyCachedInfo.fWidth < 0) {
46 SkImage::Info info;
47 if (!fDecodeProc(fData->data(), fData->size(), &info, NULL)) {
48 return false;
49 }
50 fLazilyCachedInfo = info;
51 }
52 size->set(fLazilyCachedInfo.fWidth, fLazilyCachedInfo.fHeight);
53 *config = SkImageInfoToBitmapConfig(fLazilyCachedInfo);
54 *alphaType = fLazilyCachedInfo.fAlphaType;
55 return true;
56 }
57
58 bool SkLazyCachingPixelRef::onDecode(void* pixels, size_t rowBytes) {
59 SkASSERT(pixels);
60 if (fLazilyCachedInfo.fWidth <= 0) {
61 SkISize size;
62 SkBitmap::Config config;
63 SkAlphaType alphaType;
64 // The side effect of this is to set fLazilyCachedInfo
65 this->onDecodeInfo(&size, &config, &alphaType);
66 }
67 SkBitmapFactory::Target target = {pixels, rowBytes};
68 return fDecodeProc(fData->data(), fData->size(),
69 &fLazilyCachedInfo, &target);
70 }
71
72 bool SkLazyCachingPixelRef::Install(SkBitmapFactory::DecodeProc proc,
73 SkData* data,
74 SkBitmap* destination,
75 SkScaledImageCache* cache) {
76 SkAutoTUnref<SkLazyCachingPixelRef> ref(
77 SkNEW_ARGS(SkLazyCachingPixelRef, (data, proc, cache)));
78 return ref->configure(destination) && destination->setPixelRef(ref);
79 }
80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698