blob: 0524243366c16cdf079cd8434dcd10d31500fc54 [file] [log] [blame]
reed@google.comf6627b72012-07-27 18:02:50 +00001/*
2 * Copyright 2012 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 "SkDataPixelRef.h"
9#include "SkData.h"
reed@google.com9ddef9b2012-08-07 16:10:42 +000010#include "SkFlattenableBuffers.h"
reed@google.comf6627b72012-07-27 18:02:50 +000011
12SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) {
13 fData->ref();
14 this->setPreLocked(const_cast<void*>(fData->data()), NULL);
15}
16
17SkDataPixelRef::~SkDataPixelRef() {
18 fData->unref();
19}
20
21void* SkDataPixelRef::onLockPixels(SkColorTable** ct) {
22 *ct = NULL;
23 return const_cast<void*>(fData->data());
24}
25
26void SkDataPixelRef::onUnlockPixels() {
27 // nothing to do
28}
29
30void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
31 this->INHERITED::flatten(buffer);
reed@google.comda300552013-10-14 14:33:11 +000032 buffer.writeDataAsByteArray(fData);
reed@google.comf6627b72012-07-27 18:02:50 +000033}
34
35SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer)
36 : INHERITED(buffer, NULL) {
reed@google.comda300552013-10-14 14:33:11 +000037 fData = buffer.readByteArrayAsData();
reed@google.combd5fa902012-07-31 15:19:56 +000038 this->setPreLocked(const_cast<void*>(fData->data()), NULL);
reed@google.comf6627b72012-07-27 18:02:50 +000039}