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

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

Issue 74793011: Add SkImageGenerator Interface (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: whitespace 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
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.h ('k') | src/ports/SkDiscardableMemory_none.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkDiscardablePixelRef.h"
9 #include "SkDiscardableMemory.h"
10
11 SkDiscardablePixelRef::SkDiscardablePixelRef(SkImageGenerator* generator,
12 const SkImageInfo& info,
13 size_t size,
14 size_t rowBytes)
15 : fGenerator(generator)
16 , fInfo(info)
17 , fSize(size)
18 , fRowBytes(rowBytes)
19 , fDiscardableMemory(NULL) {
20 SkASSERT(fGenerator != NULL);
21 SkASSERT(fSize > 0);
22 SkASSERT(fRowBytes > 0);
23 }
24
25 SkDiscardablePixelRef::~SkDiscardablePixelRef() {
26 SkDELETE(fGenerator);
27 }
28
29 void* SkDiscardablePixelRef::onLockPixels(SkColorTable**) {
30 if (fDiscardableMemory != NULL) {
31 if (fDiscardableMemory->lock()) {
32 return fDiscardableMemory->data();
33 }
34 fDiscardableMemory = NULL;
35 }
36 fDiscardableMemory = SkDiscardableMemory::Create(fSize);
37 if (NULL == fDiscardableMemory) {
38 return NULL; // Memory allocation failed.
39 }
40 void* pixels = fDiscardableMemory->data();
41 if (!fGenerator->getPixels(fInfo, pixels, fRowBytes)) {
42 return NULL; // TODO(halcanary) Find out correct thing to do.
43 }
44 return pixels;
45 }
46 void SkDiscardablePixelRef::onUnlockPixels() {
47 if (fDiscardableMemory != NULL) {
48 fDiscardableMemory->unlock();
49 }
50 }
51
52 bool SkDiscardablePixelRef::Install(SkImageGenerator* generator,
53 SkBitmap* dst) {
54 SkImageInfo info;
55 SkASSERT(generator != NULL);
56 if ((NULL == generator)
57 || (!generator->getInfo(&info))
58 || (!dst->setConfig(info, 0))) {
59 SkDELETE(generator);
60 return false;
61 }
62 SkAutoTUnref<SkDiscardablePixelRef> ref(SkNEW_ARGS(SkDiscardablePixelRef,
63 (generator, info,
64 dst->getSize(),
65 dst->rowBytes())));
66 dst->setPixelRef(ref);
67 return true;
68 }
OLDNEW
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.h ('k') | src/ports/SkDiscardableMemory_none.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698