blob: 7897bf93158437efa69abe1e8ea8a5baf5516ced [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
reed@google.com398337b2013-12-11 21:22:39 +000012SkDataPixelRef::SkDataPixelRef(SkData* data) : fData(data) {
reed@google.comf6627b72012-07-27 18:02:50 +000013 fData->ref();
reed@google.com398337b2013-12-11 21:22:39 +000014 this->setPreLocked(const_cast<void*>(fData->data()), NULL);
reed@google.comf6627b72012-07-27 18:02:50 +000015}
16
17SkDataPixelRef::~SkDataPixelRef() {
18 fData->unref();
19}
20
reed@google.com398337b2013-12-11 21:22:39 +000021void* SkDataPixelRef::onLockPixels(SkColorTable** ct) {
22 *ct = NULL;
23 return const_cast<void*>(fData->data());
reed@google.comf6627b72012-07-27 18:02:50 +000024}
25
26void SkDataPixelRef::onUnlockPixels() {
27 // nothing to do
28}
29
commit-bot@chromium.orgcd3b15c2013-12-04 17:06:49 +000030size_t SkDataPixelRef::getAllocatedSizeInBytes() const {
31 return fData ? fData->size() : 0;
32}
33
reed@google.comf6627b72012-07-27 18:02:50 +000034void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
35 this->INHERITED::flatten(buffer);
reed@google.comda300552013-10-14 14:33:11 +000036 buffer.writeDataAsByteArray(fData);
reed@google.comf6627b72012-07-27 18:02:50 +000037}
38
39SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer)
reed@google.com398337b2013-12-11 21:22:39 +000040 : INHERITED(buffer, NULL) {
reed@google.comda300552013-10-14 14:33:11 +000041 fData = buffer.readByteArrayAsData();
reed@google.com398337b2013-12-11 21:22:39 +000042 this->setPreLocked(const_cast<void*>(fData->data()), NULL);
reed@google.comf6627b72012-07-27 18:02:50 +000043}