1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef SkMallocPixelRef_DEFINED 18 #define SkMallocPixelRef_DEFINED 19 20 #include "SkPixelRef.h" 21 22 /** We explicitly use the same allocator for our pixels that SkMask does, 23 so that we can freely assign memory allocated by one class to the other. 24 */ 25 class SkMallocPixelRef : public SkPixelRef { 26 public: 27 /** Allocate the specified buffer for pixels. The memory is freed when the 28 last owner of this pixelref is gone. 29 */ 30 SkMallocPixelRef(void* addr, size_t size, SkColorTable* ctable); 31 virtual ~SkMallocPixelRef(); 32 33 //! Return the allocation size for the pixels getSize()34 size_t getSize() const { return fSize; } 35 36 // overrides from SkPixelRef 37 virtual void flatten(SkFlattenableWriteBuffer&) const; getFactory()38 virtual Factory getFactory() const { 39 return Create; 40 } Create(SkFlattenableReadBuffer & buffer)41 static SkPixelRef* Create(SkFlattenableReadBuffer& buffer) { 42 return SkNEW_ARGS(SkMallocPixelRef, (buffer)); 43 } 44 45 protected: 46 // overrides from SkPixelRef 47 virtual void* onLockPixels(SkColorTable**); 48 virtual void onUnlockPixels(); 49 50 SkMallocPixelRef(SkFlattenableReadBuffer& buffer); 51 52 private: 53 void* fStorage; 54 size_t fSize; 55 SkColorTable* fCTable; 56 57 typedef SkPixelRef INHERITED; 58 }; 59 60 #endif 61