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

Side by Side Diff: source/libvpx/vpx_mem/memory_manager/hmm_shrink.c

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years 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
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 11
12 /* This code is in the public domain. 12 /* This code is in the public domain.
13 ** Version: 1.1 Author: Walt Karas 13 ** Version: 1.1 Author: Walt Karas
14 */ 14 */
15 15
16 #include "hmm_intrnl.h" 16 #include "hmm_intrnl.h"
17 17
18 void U(shrink_chunk)(U(descriptor) *desc, U(size_bau) n_baus_to_shrink) 18 void U(shrink_chunk)(U(descriptor) *desc, U(size_bau) n_baus_to_shrink) {
19 { 19 head_record *dummy_end_block = (head_record *)
20 head_record *dummy_end_block = (head_record *) 20 BAUS_BACKWARD(desc->end_of_shrinkable_chunk, DU MMY_END_BLOCK_BAUS);
21 BAUS_BACKWARD(desc->end_of_shrinkable_chunk, DUMMY_END_BLOCK_BAUS);
22 21
23 #ifdef HMM_AUDIT_FAIL 22 #ifdef HMM_AUDIT_FAIL
24 23
25 if (dummy_end_block->block_size != 0) 24 if (dummy_end_block->block_size != 0)
26 /* Chunk does not have valid dummy end block. */ 25 /* Chunk does not have valid dummy end block. */
27 HMM_AUDIT_FAIL 26 HMM_AUDIT_FAIL
28 27
29 #endif 28 #endif
30 29
31 if (n_baus_to_shrink) 30 if (n_baus_to_shrink) {
32 { 31 head_record *last_block = (head_record *)
33 head_record *last_block = (head_record *) 32 BAUS_BACKWARD(
34 BAUS_BACKWARD( 33 dummy_end_block, dummy_end_block->previous_blo ck_size);
35 dummy_end_block, dummy_end_block->prev ious_block_size);
36 34
37 #ifdef HMM_AUDIT_FAIL 35 #ifdef HMM_AUDIT_FAIL
38 AUDIT_BLOCK(last_block) 36 AUDIT_BLOCK(last_block)
39 #endif 37 #endif
40 38
41 if (last_block == desc->last_freed) 39 if (last_block == desc->last_freed) {
42 { 40 U(size_bau) bs = BLOCK_BAUS(last_block);
43 U(size_bau) bs = BLOCK_BAUS(last_block);
44 41
45 /* Chunk will not be shrunk out of existence if 42 /* Chunk will not be shrunk out of existence if
46 ** 1. There is at least one allocated block in the chunk 43 ** 1. There is at least one allocated block in the chunk
47 ** and the amount to shrink is exactly the size of the 44 ** and the amount to shrink is exactly the size of the
48 ** last block, OR 45 ** last block, OR
49 ** 2. After the last block is shrunk, there will be enough 46 ** 2. After the last block is shrunk, there will be enough
50 ** BAUs left in it to form a minimal size block. */ 47 ** BAUs left in it to form a minimal size block. */
51 int chunk_will_survive = 48 int chunk_will_survive =
52 (PREV_BLOCK_BAUS(last_block) && (n_baus_to_shrink == bs)) || 49 (PREV_BLOCK_BAUS(last_block) && (n_baus_to_shrink == bs)) ||
53 (n_baus_to_shrink <= (U(size_bau))(bs - MIN_BLOCK_BAUS)); 50 (n_baus_to_shrink <= (U(size_bau))(bs - MIN_BLOCK_BAUS));
54 51
55 if (chunk_will_survive || 52 if (chunk_will_survive ||
56 (!PREV_BLOCK_BAUS(last_block) && 53 (!PREV_BLOCK_BAUS(last_block) &&
57 (n_baus_to_shrink == 54 (n_baus_to_shrink ==
58 (U(size_bau))(bs + DUMMY_END_BLOCK_BAUS)))) 55 (U(size_bau))(bs + DUMMY_END_BLOCK_BAUS)))) {
59 { 56 desc->last_freed = 0;
60 desc->last_freed = 0;
61 57
62 if (chunk_will_survive) 58 if (chunk_will_survive) {
63 { 59 bs -= n_baus_to_shrink;
64 bs -= n_baus_to_shrink;
65 60
66 if (bs) 61 if (bs) {
67 { 62 /* The last (non-dummy) block was not completely
68 /* The last (non-dummy) block was not completely 63 ** eliminated by the shrink. */
69 ** eliminated by the shrink. */
70 64
71 last_block->block_size = bs; 65 last_block->block_size = bs;
72 66
73 /* Create new dummy end record. 67 /* Create new dummy end record.
74 */ 68 */
75 dummy_end_block = 69 dummy_end_block =
76 (head_record *) BAUS_FORWARD(last_block, bs); 70 (head_record *) BAUS_FORWARD(last_block, bs);
77 dummy_end_block->previous_block_size = bs; 71 dummy_end_block->previous_block_size = bs;
78 dummy_end_block->block_size = 0; 72 dummy_end_block->block_size = 0;
79 73
80 #ifdef HMM_AUDIT_FAIL 74 #ifdef HMM_AUDIT_FAIL
81 75
82 if (desc->avl_tree_root) 76 if (desc->avl_tree_root)
83 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root) ) 77 AUDIT_BLOCK(PTR_REC_TO_HEAD(desc->avl_tree_root))
84 #endif 78 #endif
85 79
86 U(into_free_collection)(desc, last_block); 80 U(into_free_collection)(desc, last_block);
87 } 81 } else {
88 else 82 /* The last (non-dummy) block was completely
89 { 83 ** eliminated by the shrink. Make its head
90 /* The last (non-dummy) block was completely 84 ** the new dummy end block.
91 ** eliminated by the shrink. Make its head 85 */
92 ** the new dummy end block. 86 last_block->block_size = 0;
93 */ 87 last_block->previous_block_size &= ~HIGH_BIT_BAU_SIZE;
94 last_block->block_size = 0; 88 }
95 last_block->previous_block_size &= ~HIGH_BIT_BAU_SIZ E; 89 }
96 } 90 }
97 }
98 }
99 91
100 #ifdef HMM_AUDIT_FAIL 92 #ifdef HMM_AUDIT_FAIL
101 else 93 else
102 HMM_AUDIT_FAIL 94 HMM_AUDIT_FAIL
103 #endif 95 #endif
104 } 96 }
105 97
106 #ifdef HMM_AUDIT_FAIL 98 #ifdef HMM_AUDIT_FAIL
107 else 99 else
108 HMM_AUDIT_FAIL 100 HMM_AUDIT_FAIL
109 #endif 101 #endif
110 } 102 }
111 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698