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

Side by Side Diff: src/ports/SkDiscardableMemory_none.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.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | 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 2013 Google Inc. 2 * Copyright 2013 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 "SkDiscardableMemory.h" 8 #include "SkDiscardableMemory.h"
9 #include "SkTypes.h"
10
11 namespace {
12 ////////////////////////////////////////////////////////////////////////////////
13 /**
14 * Always successful, never purges. Useful for testing.
15 */
16 class SkMockDiscardableMemory : public SkDiscardableMemory {
17 public:
18 SkMockDiscardableMemory(void*);
19 virtual ~SkMockDiscardableMemory();
20 virtual bool lock() SK_OVERRIDE;
21 virtual void* data() SK_OVERRIDE;
22 virtual void unlock() SK_OVERRIDE;
23 private:
24 bool fLocked;
25 void* fPointer;
26 };
27
28 ////////////////////////////////////////////////////////////////////////////////
29
30 SkMockDiscardableMemory::SkMockDiscardableMemory(void* ptr)
31 : fLocked(true)
32 , fPointer(ptr) { // Takes ownership of ptr.
33 SkASSERT(fPointer != NULL);
34 }
35
36 SkMockDiscardableMemory::~SkMockDiscardableMemory() {
37 SkASSERT(!fLocked);
38 sk_free(fPointer);
39 }
40
41 bool SkMockDiscardableMemory::lock() {
42 SkASSERT(!fLocked);
43 return fLocked = true;
44 }
45
46 void* SkMockDiscardableMemory::data() {
47 SkASSERT(fLocked);
48 return fLocked ? fPointer : NULL;
49 }
50
51 void SkMockDiscardableMemory::unlock() {
52 SkASSERT(fLocked);
53 fLocked = false;
54 }
55 ////////////////////////////////////////////////////////////////////////////////
56 } // namespace
9 57
10 SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) { 58 SkDiscardableMemory* SkDiscardableMemory::Create(size_t bytes) {
11 return NULL; 59 void* ptr = sk_malloc_throw(bytes);
60 return (ptr != NULL) ? SkNEW_ARGS(SkMockDiscardableMemory, (ptr)) : NULL;
12 } 61 }
OLDNEW
« no previous file with comments | « src/lazy/SkDiscardablePixelRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698