aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image/SkDataPixelRef.cpp
blob: 875f933b9c1f6faa530cba41103bc8b632b4492f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkDataPixelRef.h"
#include "SkData.h"
#include "SkFlattenableBuffers.h"

SkDataPixelRef::SkDataPixelRef(const SkImageInfo& info,
                               SkData* data, size_t rowBytes)
    : INHERITED(info)
    , fData(data)
    , fRB(rowBytes) 
{
    fData->ref();
    this->setPreLocked(const_cast<void*>(fData->data()), rowBytes, NULL);
}

SkDataPixelRef::~SkDataPixelRef() {
    fData->unref();
}

bool SkDataPixelRef::onNewLockPixels(LockRec* rec) {
    rec->fPixels = const_cast<void*>(fData->data());
    rec->fColorTable = NULL;
    rec->fRowBytes = fRB;
    return true;
}

void SkDataPixelRef::onUnlockPixels() {
    // nothing to do
}

size_t SkDataPixelRef::getAllocatedSizeInBytes() const {
    return fData ? fData->size() : 0;
}

void SkDataPixelRef::flatten(SkFlattenableWriteBuffer& buffer) const {
    this->INHERITED::flatten(buffer);
    
    buffer.writeDataAsByteArray(fData);
    buffer.write32(fRB);
}

SkDataPixelRef::SkDataPixelRef(SkFlattenableReadBuffer& buffer)
    : INHERITED(buffer, NULL)
{
    fData = buffer.readByteArrayAsData();
    fRB = buffer.read32();
    this->setPreLocked(const_cast<void*>(fData->data()), fRB, NULL);
}